Flutter Development Guide
A practical guide for building cross-platform applications with Flutter 3 and Dart. Focuses on proven patterns, state management, and performance optimization.
Quick Reference
Widget Patterns
| Purpose |
Component |
| State management (simple) |
StateProvider + ConsumerWidget |
| State management (complex) |
NotifierProvider / Bloc |
| Async data |
FutureProvider / AsyncNotifierProvider |
| Real-time streams |
StreamProvider |
| Navigation |
GoRouter + context.go/push |
| Responsive layout |
LayoutBuilder + breakpoints |
| List display |
ListView.builder |
| Complex scrolling |
CustomScrollView + Slivers |
| Hooks |
HookWidget + useState/useEffect |
| Forms |
Form + TextFormField + validation |
Performance Patterns
| Purpose |
Solution |
| Prevent rebuilds |
const constructors |
| Selective updates |
ref.watch(provider.select(...)) |
| Isolate repaints |
RepaintBoundary |
| Lazy lists |
ListView.builder |
| Heavy computation |
compute() isolate |
| Image caching |
cached_network_image |
Core Principles
Widget Optimization
- Use
const constructors wherever possible
- Extract static widgets to separate const classes
- Use
Key for list items (ValueKey, ObjectKey)
- Prefer
ConsumerWidget over StatefulWidget for state
State Management
- Riverpod for dependency injection and simple state
- Bloc/Cubit for event-driven workflows and complex logic
- Never mutate state directly (create new instances)
- Use
select() to minimize rebuilds
Layout
- 8pt spacing increments (8, 16, 24, 32, 48)
- Responsive breakpoints: mobile (<650), tablet (650-1100), desktop (>1100)
- Support all screen sizes with flexible layouts
- Follow Material 3 / Cupertino design guidelines
Performance
- Profile with DevTools before optimizing
- Target <16ms frame time for 60fps
- Use
RepaintBoundary for complex animations
- Offload heavy work with
compute()
Checklist
Widget Best Practices
State Management
Navigation
Performance
Testing
References
| Topic |
Reference |
| Widget patterns, const optimization, responsive layout |
Widget Patterns |
| Riverpod providers, notifiers, async state |
Riverpod State Management |
| Bloc, Cubit, event-driven state |
Bloc State Management |
| GoRouter setup, routes, deep linking |
GoRouter Navigation |
| Feature-based structure, dependencies |
Project Structure |
| Profiling, const optimization, DevTools |
Performance Optimization |
| Widget tests, integration tests, mocking |
Testing Strategies |
| iOS/Android/Web specific implementations |
Platform Integration |
| Implicit/explicit animations, Hero, transitions |
Animations |
| Dio, interceptors, error handling, caching |
Networking |
| Form validation, FormField, input formatters |
Forms |
| i18n, flutter_localizations, intl |
Localization |
Flutter, Dart, Material Design, and Cupertino are trademarks of Google LLC and Apple Inc. respectively. Riverpod, Bloc, and GoRouter are open-source packages by their respective maintainers.
1---
2name: flutter-dev
3description: |
4 Flutter cross-platform development guide covering widget patterns, Riverpod/Bloc state management, GoRouter navigation, performance optimization, and platform-specific implementations. Includes const optimization, responsive layouts, testing strategies, and DevTools profiling.
5 Use when: building Flutter apps, implementing state management (Riverpod/Bloc), setting up GoRouter navigation, creating custom widgets, optimizing performance, writing widget tests, cross-platform development.
6description_zh: "Flutter 跨平台开发指南"
7description_en: "Flutter cross-platform dev guide (Riverpod, GoRouter)"
8license: MIT
9metadata:
10 version: "1.0.0"
11 category: mobile
12 sources:
13 - Flutter Documentation
14 - Riverpod Documentation
15 - Bloc Library Documentation
16---
17
18# Flutter Development Guide
19
20A practical guide for building cross-platform applications with Flutter 3 and Dart. Focuses on proven patterns, state management, and performance optimization.
21
22## Quick Reference
23
24### Widget Patterns
25
26| Purpose | Component |
27|---------|-----------|
28| State management (simple) | `StateProvider` + `ConsumerWidget` |
29| State management (complex) | `NotifierProvider` / `Bloc` |
30| Async data | `FutureProvider` / `AsyncNotifierProvider` |
31| Real-time streams | `StreamProvider` |
32| Navigation | `GoRouter` + `context.go/push` |
33| Responsive layout | `LayoutBuilder` + breakpoints |
34| List display | `ListView.builder` |
35| Complex scrolling | `CustomScrollView` + Slivers |
36| Hooks | `HookWidget` + `useState/useEffect` |
37| Forms | `Form` + `TextFormField` + validation |
38
39### Performance Patterns
40
41| Purpose | Solution |
42|---------|----------|
43| Prevent rebuilds | `const` constructors |
44| Selective updates | `ref.watch(provider.select(...))` |
45| Isolate repaints | `RepaintBoundary` |
46| Lazy lists | `ListView.builder` |
47| Heavy computation | `compute()` isolate |
48| Image caching | `cached_network_image` |
49
50## Core Principles
51
52### Widget Optimization
53- Use `const` constructors wherever possible
54- Extract static widgets to separate const classes
55- Use `Key` for list items (ValueKey, ObjectKey)
56- Prefer `ConsumerWidget` over `StatefulWidget` for state
57
58### State Management
59- Riverpod for dependency injection and simple state
60- Bloc/Cubit for event-driven workflows and complex logic
61- Never mutate state directly (create new instances)
62- Use `select()` to minimize rebuilds
63
64### Layout
65- 8pt spacing increments (8, 16, 24, 32, 48)
66- Responsive breakpoints: mobile (<650), tablet (650-1100), desktop (>1100)
67- Support all screen sizes with flexible layouts
68- Follow Material 3 / Cupertino design guidelines
69
70### Performance
71- Profile with DevTools before optimizing
72- Target <16ms frame time for 60fps
73- Use `RepaintBoundary` for complex animations
74- Offload heavy work with `compute()`
75
76## Checklist
77
78### Widget Best Practices
79- [ ] `const` constructors on all static widgets
80- [ ] Proper `Key` on list items
81- [ ] `ConsumerWidget` for state-dependent widgets
82- [ ] No widget building inside `build()` method
83- [ ] Extract reusable widgets to separate files
84
85### State Management
86- [ ] Immutable state objects
87- [ ] `select()` for granular rebuilds
88- [ ] Proper provider scoping
89- [ ] Dispose controllers and subscriptions
90- [ ] Handle loading/error states
91
92### Navigation
93- [ ] GoRouter with typed routes
94- [ ] Auth guards via redirect
95- [ ] Deep linking support
96- [ ] State preservation across routes
97
98### Performance
99- [ ] Profile mode testing (`flutter run --profile`)
100- [ ] <16ms frame rendering time
101- [ ] No unnecessary rebuilds (DevTools check)
102- [ ] Images cached and resized
103- [ ] Heavy computation in isolates
104
105### Testing
106- [ ] Widget tests for UI components
107- [ ] Unit tests for business logic
108- [ ] Integration tests for user flows
109- [ ] Bloc tests with `blocTest()`
110
111## References
112
113| Topic | Reference |
114|-------|-----------|
115| Widget patterns, const optimization, responsive layout | [Widget Patterns](references/widget-patterns.md) |
116| Riverpod providers, notifiers, async state | [Riverpod State Management](references/riverpod-state.md) |
117| Bloc, Cubit, event-driven state | [Bloc State Management](references/bloc-state.md) |
118| GoRouter setup, routes, deep linking | [GoRouter Navigation](references/gorouter-navigation.md) |
119| Feature-based structure, dependencies | [Project Structure](references/project-structure.md) |
120| Profiling, const optimization, DevTools | [Performance Optimization](references/performance.md) |
121| Widget tests, integration tests, mocking | [Testing Strategies](references/testing.md) |
122| iOS/Android/Web specific implementations | [Platform Integration](references/platform-specific.md) |
123| Implicit/explicit animations, Hero, transitions | [Animations](references/animations.md) |
124| Dio, interceptors, error handling, caching | [Networking](references/networking.md) |
125| Form validation, FormField, input formatters | [Forms](references/forms.md) |
126| i18n, flutter_localizations, intl | [Localization](references/localization.md) |
127
128---
129
130Flutter, Dart, Material Design, and Cupertino are trademarks of Google LLC and Apple Inc. respectively. Riverpod, Bloc, and GoRouter are open-source packages by their respective maintainers.