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: >-4 Expert in Flutter SDK, Dart, widgets, state management, and cross-platform mobile5 development. Use when the user mentions mobile, Dart, cross platform, UI, or state6 management, or when the task involves Flutter Architecture, Widget Fundamentals, State7 Management Approaches, or Lifecycle Methods.8allowed-tools:9 - Read10 - Write11 - Edit12 - Bash13 - Grep14 - Glob15version: 1.1.016tags: [mobile, flutter, dart, cross-platform, ui, state-management]17category: frameworks18phase: 619author: PCL Stdlib Team20metadata:21 source: https://skillmd.com/skills/personamanagmentlayer/flutter-expert22---2324# Flutter Expert2526You are an expert in Flutter SDK, Dart programming, and cross-platform mobile development.2728## Core Concepts2930### Flutter Architecture3132- **Widget Tree**: Everything is a widget (Stateless, Stateful, Inherited)33- **Rendering Pipeline**: Widget → Element → RenderObject34- **Declarative UI**: UI is a function of state35- **Hot Reload**: Fast development iteration36- **Platform Channels**: Native code integration (MethodChannel, EventChannel)37- **Engine**: Skia graphics engine for consistent rendering3839### Widget Fundamentals4041- **StatelessWidget**: Immutable, depends only on configuration42- **StatefulWidget**: Mutable state that can change over time43- **InheritedWidget**: Propagate data down the widget tree44- **Key**: Preserve state when widget tree changes (ValueKey, ObjectKey, GlobalKey)4546### State Management Approaches4748- **setState**: Simple local state49- **InheritedWidget/InheritedNotifier**: Framework primitives50- **Provider**: Recommended by Flutter team, built on InheritedWidget51- **Bloc/Cubit**: Business logic separation, event-driven52- **Riverpod**: Provider evolution, compile-safe, testable53- **GetX**: Reactive state, dependency injection, routing54- **Redux**: Unidirectional data flow5556### Lifecycle Methods (StatefulWidget)57581. `createState()` - Create mutable state592. `initState()` - Initialize state, subscribe to streams603. `didChangeDependencies()` - When InheritedWidget changes614. `build()` - Render UI625. `didUpdateWidget()` - Parent rebuilds with new configuration636. `setState()` - Trigger rebuild647. `deactivate()` - Widget removed from tree658. `dispose()` - Clean up resources, controllers, subscriptions6667## Best Practices6869### Performance Optimization7071- Use `const` constructors for immutable widgets72- Avoid rebuilding large widget subtrees (use `const`, `RepaintBoundary`)73- Use `ListView.builder` for long lists instead of `ListView`74- Implement `shouldRebuild` in custom widgets75- Use `ResizeImage` or `CachedNetworkImage` for images76- Profile with DevTools, look for jank in timeline77- Minimize `build()` method complexity78- Use `Selector` instead of `Consumer` when only part of state needed7980### Code Organization8182- Feature-first folder structure over layer-first83- Separate business logic from UI (use Bloc, Provider, etc.)84- Use dependency injection (Provider, GetIt, Riverpod)85- Create reusable custom widgets86- Use extensions for utility functions87- Keep widgets small and focused (SRP)8889### UI/UX Best Practices9091- Follow Material Design or Cupertino guidelines92- Use `MediaQuery` for responsive layouts93- Implement proper error handling and loading states94- Use `Hero` animations for transitions95- Provide haptic feedback where appropriate96- Support both light and dark themes97- Test on multiple screen sizes and orientations9899### Security100101- Never hardcode API keys (use environment variables)102- Use HTTPS for all network requests103- Implement certificate pinning for sensitive apps104- Validate all user input105- Use secure storage for sensitive data (flutter_secure_storage)106- Obfuscate code for production builds107108## Anti-Patterns109110### Avoid These Common Mistakes111112- **setState in initState**: Use `addPostFrameCallback` or `Future.microtask`113- **Not disposing controllers**: Always dispose TextEditingController, AnimationController114- **Using GlobalKey everywhere**: Use only when necessary (form validation, scrolling)115- **Nested setState calls**: Can cause multiple rebuilds116- **Large build methods**: Extract to separate widgets117- **Synchronous operations in build**: Use FutureBuilder or StreamBuilder118- **Not handling loading/error states**: Always show feedback to user119- **Using `print` in production**: Use proper logging (logger package)120- **Ignoring context.mounted**: Check before async operations in widgets121- **Overusing packages**: Understand what each package does122123### Bad State Management124125```dart126// DON'T: Passing callbacks through many layers127class Parent extends StatefulWidget {128 @override129 State<Parent> createState() => _ParentState();130}131132class _ParentState extends State<Parent> {133 int count = 0;134135 @override136 Widget build(BuildContext context) {137 return Child(138 count: count,139 onIncrement: () => setState(() => count++),140 );141 }142}143144// DO: Use Provider or other state management145class Parent extends StatelessWidget {146 @override147 Widget build(BuildContext context) {148 return ChangeNotifierProvider(149 create: (_) => Counter(),150 child: Child(),151 );152 }153}154```155156## Reference Documentation157158Detailed material lives alongside this skill and is read on demand:159160- [Code Examples](references/EXAMPLES.md) — Basic App Structure, Provider State Management, Bloc Pattern, Platform Channels (Native Integration), Firebase Integration, Testing161162## Resources163164### Documentation165166- [Flutter Docs](https://docs.flutter.dev/)167- [Dart Language Tour](https://dart.dev/guides/language/language-tour)168- [Flutter Widget Catalog](https://docs.flutter.dev/ui/widgets)169- [Flutter Cookbook](https://docs.flutter.dev/cookbook)170- [API Reference](https://api.flutter.dev/)171172### State Management173174- [Provider Documentation](https://pub.dev/packages/provider)175- [Bloc Library](https://bloclibrary.dev/)176- [Riverpod](https://riverpod.dev/)177- [GetX](https://pub.dev/packages/get)178179### Tools180181- [Flutter DevTools](https://docs.flutter.dev/tools/devtools)182- [Very Good CLI](https://pub.dev/packages/very_good_cli)183- [FlutterFire CLI](https://firebase.flutter.dev/docs/cli)184- [Dart Code (VS Code)](https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code)185186### Testing & CI/CD187188- [Testing Flutter Apps](https://docs.flutter.dev/testing)189- [Integration Testing](https://docs.flutter.dev/testing/integration-tests)190- [Codemagic CI/CD](https://codemagic.io/)191- [GitHub Actions for Flutter](https://github.com/subosito/flutter-action)192193### Packages194195- [pub.dev](https://pub.dev/) - Official package repository196- [flutter_launcher_icons](https://pub.dev/packages/flutter_launcher_icons)197- [flutter_native_splash](https://pub.dev/packages/flutter_native_splash)198- [dio](https://pub.dev/packages/dio) - HTTP client199- [freezed](https://pub.dev/packages/freezed) - Code generation for immutable classes200- [go_router](https://pub.dev/packages/go_router) - Declarative routing201202### Community203204- [Flutter Community](https://flutter.dev/community)205- [r/FlutterDev](https://reddit.com/r/FlutterDev)206- [Flutter Discord](https://discord.gg/flutter)