When to activate
- Building Flutter applications with Dart
- Composing complex widget trees with reusable components
- Implementing state management with Riverpod, Bloc, or Provider
- Creating platform channels for native iOS/Android integration
- Optimizing Flutter app performance and build size
When NOT to use
- For React Native apps (use react-native-expo)
- For pure native development
- For backend/Dart server development
Instructions
- Project structure. Feature-first:
lib/features/auth/,lib/features/feed/,lib/core/,lib/shared/. - Widget composition. Build small, focused widgets. Use
constconstructors. Prefer composition over inheritance. - State management. Riverpod for compile-safe state:
StateNotifierfor complex state,AsyncNotifierfor async operations. - Platform channels. MethodChannel for one-off calls, EventChannel for streams. Handle platform-specific UI with
Platform.isIOS. - Navigation. GoRouter for declarative routing with deep link support. Define routes as constants.
- Performance. Use
RepaintBoundaryfor expensive widgets,ListView.builderfor long lists, avoidsetStateon parent widgets. - Testing. Widget tests for UI, integration tests with
patrolorintegration_test, unit tests for business logic.
Example
// Riverpod state management
final cartProvider = StateNotifierProvider<CartNotifier, CartState>((ref) {
return CartNotifier(ref.read(apiProvider));
});
class CartNotifier extends StateNotifier<CartState> {
CartNotifier(this._api) : super(CartState.initial());
final ApiClient _api;
Future<void> addItem(Product product) async {
state = state.copyWith(isLoading: true);
final updated = await _api.addToCart(product.id);
state = CartState(items: updated, isLoading: false);
}
}