| name | flutter-dev-protocol |
| description | Development protocol for mobile-dev agent working with Flutter (primary) and React Native (secondary). Covers project detection, architecture patterns, state management conventions, testing, and platform-specific guidelines. Automatically loaded by the mobile-dev agent. |
| user-invokable | false |
Flutter Development Protocol
Project Detection
On task start, auto-detect the project type:
- Check for
pubspec.yaml → Flutter project
- Check for
package.json with react-native dependency → React Native project
- If neither found → report to team-lead, this may be a new project setup
Flutter Mode (Primary)
Project Setup Checklist
Before starting work on a new Flutter project:
- Verify
pubspec.yaml dependencies:
flutter_riverpod or riverpod for state management
go_router for routing
flutter_test in dev_dependencies
integration_test in dev_dependencies
- Check
analysis_options.yaml for strict linting rules
- Scan
lib/ for existing architecture patterns (feature-first, layer-first)
- Read existing screens and widgets to understand naming conventions
State Management: Riverpod
Use Riverpod as the default state management solution:
// lib/features/products/presentation/providers/product_provider.dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
final productListProvider = FutureProvider.autoDispose<List<Product>>((ref) async {
final repository = ref.read(productRepositoryProvider);
return repository.getProducts();
});
Rules:
- Use
ConsumerWidget or ConsumerStatefulWidget (not StatelessWidget + Consumer)
- Use
autoDispose for providers that should clean up when no longer listened to
- Keep providers focused — one concern per provider
- Use
ref.watch in build methods, ref.read in callbacks
Routing: GoRouter
// lib/core/router/app_router.dart
final routerProvider = Provider<GoRouter>((ref) {
return GoRouter(
routes: [
GoRoute(path: '/', builder: (_, __) => const HomeScreen()),
GoRoute(path: '/products/:id', builder: (_, state) =>
ProductDetailScreen(id: state.pathParameters['id']!)),
],
);
});
Widget Conventions
- Always use
const constructors when possible
- Extract widgets — if a build method exceeds ~50 lines, extract sub-widgets
- Use
Key for list items — ValueKey(item.id) for lists
- Platform-aware — use
Platform.isIOS / Platform.isAndroid for platform-specific behavior
- Responsive — use
LayoutBuilder or MediaQuery for adaptive layouts
Testing Protocol
flutter test test/unit/ --reporter=expanded
flutter test test/widget/ --reporter=expanded
flutter test integration_test/ --reporter=expanded
flutter test --reporter=expanded
Test structure:
test/
├── unit/
│ └── features/
│ └── products/
│ └── product_repository_test.dart
├── widget/
│ └── features/
│ └── products/
│ └── product_card_test.dart
└── helpers/
├── test_helper.dart
└── mocks.dart
Build & Verify
dart analyze
dart format --set-exit-if-changed lib/ test/
flutter build apk --debug
flutter build ios --debug --no-codesign
React Native Mode (Secondary)
When working on a React Native project, adapt these patterns:
State Management
- Zustand (simple) or Redux Toolkit (complex)
- React Query for server state
Testing
npx jest --passWithNoTests
Build
npx react-native run-android
npx react-native run-ios
Branch Naming for Mobile
mobile/<task-id>-<short-description>
Examples:
mobile/task-010-product-listing-screen
mobile/task-011-cart-provider
mobile/task-012-checkout-flow
Domain Boundary Reminder
You may ONLY modify:
- Flutter:
lib/, android/, ios/, test/, integration_test/, pubspec.yaml, analysis_options.yaml
- React Native:
src/, android/, ios/, __tests__/, package.json (dependencies only, with team-lead approval)
NEVER modify shared types, backend code, or web frontend code.