A copilot-instructions.md template for Flutter projects with Riverpod, GoRouter, and clean architecture widget patterns.
## copilot-instructions.md for Flutter Projects This is a Flutter 3.24 project with Dart 3.5. Follow these conventions: ### Architecture - Feature-first directory structure: `lib/features/auth/`, `lib/features/home/` - Each feature contains: `presentation/`, `domain/`, `data/` layers - Shared code in `lib/core/`: theme, routing, networking, constants - Use Riverpod for state management and dependency injection ### Widget Conventions - Prefer `StatelessWidget` with Riverpod `ConsumerWidget` for state - Use `const` constructors on all widgets that accept only compile-time constants - Extract widgets into separate files when they exceed 80 lines - Name files in `snake_case.dart`, classes in `PascalCase` - Widget key parameter: use `Key?` for list items and dynamic widgets ### State Management (Riverpod) - `@riverpod` annotation with code generation for providers - `AsyncNotifierProvider` for async state with loading/error/data - `StateNotifierProvider` for complex synchronous state - Keep providers in `providers/` directory within each feature - Never read providers in `build()`; use `ref.watch()` instead ### Routing (GoRouter) - Route definitions in `lib/core/routing/app_router.dart` - Named routes with path parameters: `GoRoute(path: '/user/:id')` - Shell routes for persistent navigation (bottom tab bar) - Redirect guards for authentication: redirect to `/login` if unauthenticated - Use `context.go()` for navigation, `context.push()` for stack navigation ### Networking - Dio HTTP client with interceptors for auth token injection - Repository pattern: abstract class defining contract, implementation with Dio - Model classes with `freezed` for immutability and JSON serialization - Use `json_serializable` with `@JsonKey` for field mapping - Handle connectivity: show offline banner, queue mutations ### UI / UX - Material 3 with custom `ThemeData` in `lib/core/theme/` - Responsive layouts with `LayoutBuilder` and `MediaQuery` - Support both light and dark themes - Use `SliverAppBar` and `CustomScrollView` for complex scrolling - Loading shimmer effects with `shimmer` package - Error widgets with retry buttons for failed data loads ### Testing - Widget tests with `testWidgets()` and `WidgetTester` - Unit tests for providers, repositories, and business logic - Golden tests for visual regression: `matchesGoldenFile()` - Use `ProviderScope.overrides` to mock providers in tests - Integration tests in `integration_test/` directory
Free to copy and use. Compatible with GitHub Copilot, GPT-5.
Save as .github/copilot-instructions.md in your Flutter repository. Modify the state management and routing sections if using different packages.
Initial release
Sign in and download this prompt to leave a review.