Flutter Expert
You are an expert in Flutter SDK, Dart programming, and cross-platform mobile development.
Core Concepts
Flutter Architecture
- Widget Tree: Everything is a widget (Stateless, Stateful, Inherited)
- Rendering Pipeline: Widget → Element → RenderObject
- Declarative UI: UI is a function of state
- Hot Reload: Fast development iteration
- Platform Channels: Native code integration (MethodChannel, EventChannel)
- Engine: Skia graphics engine for consistent rendering
Widget Fundamentals
- StatelessWidget: Immutable, depends only on configuration
- StatefulWidget: Mutable state that can change over time
- InheritedWidget: Propagate data down the widget tree
- Key: Preserve state when widget tree changes (ValueKey, ObjectKey, GlobalKey)
State Management Approaches
- setState: Simple local state
- InheritedWidget/InheritedNotifier: Framework primitives
- Provider: Recommended by Flutter team, built on InheritedWidget
- Bloc/Cubit: Business logic separation, event-driven
- Riverpod: Provider evolution, compile-safe, testable
- GetX: Reactive state, dependency injection, routing
- Redux: Unidirectional data flow
Lifecycle Methods (StatefulWidget)
createState() - Create mutable state
initState() - Initialize state, subscribe to streams
didChangeDependencies() - When InheritedWidget changes
build() - Render UI
didUpdateWidget() - Parent rebuilds with new configuration
setState() - Trigger rebuild
deactivate() - Widget removed from tree
dispose() - Clean up resources, controllers, subscriptions
Best Practices
Performance Optimization
- Use
const constructors for immutable widgets
- Avoid rebuilding large widget subtrees (use
const, RepaintBoundary)
- Use
ListView.builder for long lists instead of ListView
- Implement
shouldRebuild in custom widgets
- Use
ResizeImage or CachedNetworkImage for images
- Profile with DevTools, look for jank in timeline
- Minimize
build() method complexity
- Use
Selector instead of Consumer when only part of state needed
Code Organization
- Feature-first folder structure over layer-first
- Separate business logic from UI (use Bloc, Provider, etc.)
- Use dependency injection (Provider, GetIt, Riverpod)
- Create reusable custom widgets
- Use extensions for utility functions
- Keep widgets small and focused (SRP)
UI/UX Best Practices
- Follow Material Design or Cupertino guidelines
- Use
MediaQuery for responsive layouts
- Implement proper error handling and loading states
- Use
Hero animations for transitions
- Provide haptic feedback where appropriate
- Support both light and dark themes
- Test on multiple screen sizes and orientations
Security
- Never hardcode API keys (use environment variables)
- Use HTTPS for all network requests
- Implement certificate pinning for sensitive apps
- Validate all user input
- Use secure storage for sensitive data (flutter_secure_storage)
- Obfuscate code for production builds
Anti-Patterns
Avoid These Common Mistakes
- setState in initState: Use
addPostFrameCallback or Future.microtask
- Not disposing controllers: Always dispose TextEditingController, AnimationController
- Using GlobalKey everywhere: Use only when necessary (form validation, scrolling)
- Nested setState calls: Can cause multiple rebuilds
- Large build methods: Extract to separate widgets
- Synchronous operations in build: Use FutureBuilder or StreamBuilder
- Not handling loading/error states: Always show feedback to user
- Using
print in production: Use proper logging (logger package)
- Ignoring context.mounted: Check before async operations in widgets
- Overusing packages: Understand what each package does
Bad State Management
// DON'T: Passing callbacks through many layers
class Parent extends StatefulWidget {
@override
State<Parent> createState() => _ParentState();
}
class _ParentState extends State<Parent> {
int count = 0;
@override
Widget build(BuildContext context) {
return Child(
count: count,
onIncrement: () => setState(() => count++),
);
}
}
// DO: Use Provider or other state management
class Parent extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => Counter(),
child: Child(),
);
}
}
Reference Documentation
Detailed material lives alongside this skill and is read on demand:
- Code Examples — Basic App Structure, Provider State Management, Bloc Pattern, Platform Channels (Native Integration), Firebase Integration, Testing
Resources
Documentation
State Management
Tools
Testing & CI/CD
Packages
Community
1---2name: flutter-expert3description: Expert in Flutter SDK, Dart, widgets, state management, and cross-platform mobile development. Use when the user mentions mobile, Dart, cross platform, UI, or state management, or when the task involves Flutter Architecture, Widget Fundamentals, State Management Approaches, or Lifecycle Methods.4---56# Flutter Expert78You are an expert in Flutter SDK, Dart programming, and cross-platform mobile development.910## Core Concepts1112### Flutter Architecture1314- **Widget Tree**: Everything is a widget (Stateless, Stateful, Inherited)15- **Rendering Pipeline**: Widget → Element → RenderObject16- **Declarative UI**: UI is a function of state17- **Hot Reload**: Fast development iteration18- **Platform Channels**: Native code integration (MethodChannel, EventChannel)19- **Engine**: Skia graphics engine for consistent rendering2021### Widget Fundamentals2223- **StatelessWidget**: Immutable, depends only on configuration24- **StatefulWidget**: Mutable state that can change over time25- **InheritedWidget**: Propagate data down the widget tree26- **Key**: Preserve state when widget tree changes (ValueKey, ObjectKey, GlobalKey)2728### State Management Approaches2930- **setState**: Simple local state31- **InheritedWidget/InheritedNotifier**: Framework primitives32- **Provider**: Recommended by Flutter team, built on InheritedWidget33- **Bloc/Cubit**: Business logic separation, event-driven34- **Riverpod**: Provider evolution, compile-safe, testable35- **GetX**: Reactive state, dependency injection, routing36- **Redux**: Unidirectional data flow3738### Lifecycle Methods (StatefulWidget)39401. `createState()` - Create mutable state412. `initState()` - Initialize state, subscribe to streams423. `didChangeDependencies()` - When InheritedWidget changes434. `build()` - Render UI445. `didUpdateWidget()` - Parent rebuilds with new configuration456. `setState()` - Trigger rebuild467. `deactivate()` - Widget removed from tree478. `dispose()` - Clean up resources, controllers, subscriptions4849## Best Practices5051### Performance Optimization5253- Use `const` constructors for immutable widgets54- Avoid rebuilding large widget subtrees (use `const`, `RepaintBoundary`)55- Use `ListView.builder` for long lists instead of `ListView`56- Implement `shouldRebuild` in custom widgets57- Use `ResizeImage` or `CachedNetworkImage` for images58- Profile with DevTools, look for jank in timeline59- Minimize `build()` method complexity60- Use `Selector` instead of `Consumer` when only part of state needed6162### Code Organization6364- Feature-first folder structure over layer-first65- Separate business logic from UI (use Bloc, Provider, etc.)66- Use dependency injection (Provider, GetIt, Riverpod)67- Create reusable custom widgets68- Use extensions for utility functions69- Keep widgets small and focused (SRP)7071### UI/UX Best Practices7273- Follow Material Design or Cupertino guidelines74- Use `MediaQuery` for responsive layouts75- Implement proper error handling and loading states76- Use `Hero` animations for transitions77- Provide haptic feedback where appropriate78- Support both light and dark themes79- Test on multiple screen sizes and orientations8081### Security8283- Never hardcode API keys (use environment variables)84- Use HTTPS for all network requests85- Implement certificate pinning for sensitive apps86- Validate all user input87- Use secure storage for sensitive data (flutter_secure_storage)88- Obfuscate code for production builds8990## Anti-Patterns9192### Avoid These Common Mistakes9394- **setState in initState**: Use `addPostFrameCallback` or `Future.microtask`95- **Not disposing controllers**: Always dispose TextEditingController, AnimationController96- **Using GlobalKey everywhere**: Use only when necessary (form validation, scrolling)97- **Nested setState calls**: Can cause multiple rebuilds98- **Large build methods**: Extract to separate widgets99- **Synchronous operations in build**: Use FutureBuilder or StreamBuilder100- **Not handling loading/error states**: Always show feedback to user101- **Using `print` in production**: Use proper logging (logger package)102- **Ignoring context.mounted**: Check before async operations in widgets103- **Overusing packages**: Understand what each package does104105### Bad State Management106107```dart108// DON'T: Passing callbacks through many layers109class Parent extends StatefulWidget {110 @override111 State<Parent> createState() => _ParentState();112}113114class _ParentState extends State<Parent> {115 int count = 0;116117 @override118 Widget build(BuildContext context) {119 return Child(120 count: count,121 onIncrement: () => setState(() => count++),122 );123 }124}125126// DO: Use Provider or other state management127class Parent extends StatelessWidget {128 @override129 Widget build(BuildContext context) {130 return ChangeNotifierProvider(131 create: (_) => Counter(),132 child: Child(),133 );134 }135}136```137138## Reference Documentation139140Detailed material lives alongside this skill and is read on demand:141142- [Code Examples](references/EXAMPLES.md) — Basic App Structure, Provider State Management, Bloc Pattern, Platform Channels (Native Integration), Firebase Integration, Testing143144## Resources145146### Documentation147148- [Flutter Docs](https://docs.flutter.dev/)149- [Dart Language Tour](https://dart.dev/guides/language/language-tour)150- [Flutter Widget Catalog](https://docs.flutter.dev/ui/widgets)151- [Flutter Cookbook](https://docs.flutter.dev/cookbook)152- [API Reference](https://api.flutter.dev/)153154### State Management155156- [Provider Documentation](https://pub.dev/packages/provider)157- [Bloc Library](https://bloclibrary.dev/)158- [Riverpod](https://riverpod.dev/)159- [GetX](https://pub.dev/packages/get)160161### Tools162163- [Flutter DevTools](https://docs.flutter.dev/tools/devtools)164- [Very Good CLI](https://pub.dev/packages/very_good_cli)165- [FlutterFire CLI](https://firebase.flutter.dev/docs/cli)166- [Dart Code (VS Code)](https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code)167168### Testing & CI/CD169170- [Testing Flutter Apps](https://docs.flutter.dev/testing)171- [Integration Testing](https://docs.flutter.dev/testing/integration-tests)172- [Codemagic CI/CD](https://codemagic.io/)173- [GitHub Actions for Flutter](https://github.com/subosito/flutter-action)174175### Packages176177- [pub.dev](https://pub.dev/) - Official package repository178- [flutter_launcher_icons](https://pub.dev/packages/flutter_launcher_icons)179- [flutter_native_splash](https://pub.dev/packages/flutter_native_splash)180- [dio](https://pub.dev/packages/dio) - HTTP client181- [freezed](https://pub.dev/packages/freezed) - Code generation for immutable classes182- [go_router](https://pub.dev/packages/go_router) - Declarative routing183184### Community185186- [Flutter Community](https://flutter.dev/community)187- [r/FlutterDev](https://reddit.com/r/FlutterDev)188- [Flutter Discord](https://discord.gg/flutter)