Flutter app architecture, state management and packages (2026 survey)
flutterdartarchitectureriverpodblocpackagesanimationmvvm
A survey of community best practice for structuring a professional Flutter app, compiled in March 2026 for the SMC site rebuild. It is a snapshot of consensus and pub.dev popularity, not something each item was proven on; use it as a starting point when choosing a stack. Package "likes" figures are from that date.
Architecture
- Flutter's official recommendation is MVVM: View, ViewModel, Repository, Service.
- Feature-first folders with clean layering inside each feature:
lib/ core/ # theme, constants, utils, base classes shared/ # reusable widgets, common services features/<name>/{data,domain,presentation}/ - Repository pattern: abstracts data sources, converts DTOs (data layer) into domain models, handles caching.
- SOLID in Flutter terms: widgets only render; logic lives in services, view models or blocs;
depend on small abstract interfaces (
UserRepository, notDataService) wired at a composition root. - Composition over inheritance; extract subtrees into separate widget classes rather than
helper methods (they get their own element and can be
const). - Errors: Dart 3 sealed
Result<T>classes with exhaustiveswitch, orfpdart'sEither; global handlers viaFlutterError.onError,PlatformDispatcher.instance.onErrorandErrorWidget.builder. - Immutability:
freezedfor models withcopyWith, equality, JSON and unions; plain Dart 3 sealed classes for simple cases. - Naming:
UpperCamelCasetypes,lowerCamelCasemembers,snake_casefiles, one public class per file;very_good_analysisfor strict lints.
State management ranking (March 2026)
- Riverpod 3 as the default: compile-time safe, little boilerplate, async-first.
- BLoC/Cubit for event-driven or audit-heavy apps (use Cubit about 80% of the time, full
BLoC for the rest; immutable states; never pass a
BuildContextinto a bloc). - Provider is now mainly for beginners (Riverpod is its successor).
- GetX not recommended (tight coupling, hard to test).
- Signals emerging for fine-grained reactivity.
Responsive layout and theming
MediaQuery.sizeOf(context)for the viewport,LayoutBuilderfor container-relative layout.- Material 3 breakpoints: compact under 600, medium 600 to 840, expanded over 840.
- Material 3 with
ColorScheme.fromSeed(),ThemeExtensionfor custom design tokens, semantic color roles everywhere (never hardcoded colors), theme split acrossapp_theme.dart,color_schemes.dart,text_themes.dart.
Animation guidance
- Implicit animations (
AnimatedContainer,AnimatedOpacity,AnimatedSwitcher,TweenAnimationBuilder) cover about 80% of needs; explicitAnimationController+Tweenfor loops, sequences and gesture-driven motion. - Material motion patterns (
animationspackage): container transform (card to detail), shared axis (steps, tabs), fade through (bottom-nav switches), fade scale (dialogs, FABs). - Durations: 100 to 200 ms for color, opacity and micro-interactions; 200 to 400 ms for page
transitions and expand/collapse; 400 to 700 ms for choreography. Curves:
Curves.easeInOutCubicEmphasized(M3 primary),easeOutentering,easeInleaving. - Skeleton screens beat spinners (
skeletonizerbuilds them from the real layout). -
Rive over Lottie on Flutter web: files 10 to 15 times smaller and much better frame rates, with interactive state machines; Lottie wins on its library of ready-made animations.
-
Applied in TLDR (v1.18, March 2026): replace hardcoded
Duration(milliseconds: N)with M3 tokens (Durations.short4200 ms,medium1250,medium2300) andEasing.emphasizedDeceleratefor entrances,Easing.standardotherwise;HapticFeedback.lightImpact()on votes, bookmarks and reactions,selectionClick()on segmented toggles; staggered list entry (50 ms per item, capped at the 10th item so long lists do not crawl in);SegmentedButtoninstead of hand-made toggle pills;NavigationRailat 600 px and extended with labels at 840 px; 48 dp minimum touch targets. Snackbar and tooltip traps are in Flutter and Dart gotchas (collections, widgets, theming).
Package shortlist
| Need | Package |
|---|---|
| State | flutter_riverpod (or flutter_bloc) |
| Routing | go_router (official; deep links, redirects, shell routes) |
| HTTP | dio with an interceptor chain (auth, logging, retry, cache); retrofit for typed clients |
| Models | freezed, json_serializable, build_runner |
| DI | get_it (+ injectable) |
| Theming | flex_color_scheme, google_fonts |
| Animation | flutter_animate, animations, rive, lottie |
| Images/SVG | cached_network_image, flutter_svg, extended_image |
| Charts | fl_chart |
| Lists/grids | infinite_scroll_pagination, flutter_staggered_grid_view, scrollable_positioned_list |
| Forms | flutter_form_builder |
| Loading | skeletonizer, shimmer |
| Testing | mocktail, alchemist (goldens), patrol (E2E) |
| Rich text | flutter_quill, flutter_markdown, flutter_html |
| Adaptive nav | flutter_adaptive_scaffold |
Lessons from a real codebase (Run, 2026 audits)
Run is Justin's Flutter/Flame game (about two years of features, audited 2026-03 and 2026-10).
What actually hurt, in rough order:
- Untyped API responses: ApiResponse.body as dynamic forced as Map casts everywhere,
and malformed JSON crashed at runtime. Typed models (LeaderboardEntry, PersonalBest, ...)
fixed a whole bug class. Add a 30 s HTTP timeout too; without it a network hiccup was an
instant silent failure.
- God classes: the game world, player and editor screen reached 600-2000+ lines; extracting
managers (checkpoints, deaths, dimensions, ghosts, rotation) made them testable.
- Singletons everywhere (static final instance) made mocking impossible. DI (get_it or
Riverpod) or at least injectable constructors pay off once tests exist. A global singleton is
still fine for genuinely app-wide state (Run's cheat manager must exist before any game does).
- No router: 36 files built inline MaterialPageRoutes and a screen took 7 optional
constructor params to know which level to show. Use go_router and typed route params from
the start (go_router navigation patterns and opening your own links in-app).
- Theme bypassed: 194 raw Color(...) literals in screens while an AppColors class sat
unused.
- Layering inverted: a runtime factory lived in the editor's models folder and imported ~30
game components, while game files imported editor models. Keep a neutral model package that
both depend on.
- Magic numbers (grid 32, 5-frame cooldowns, 300 ms freezes) belong in named constants;
stringly-typed values ('DIAMOND') belong in enums; scattered debugPrint wants a logger.
- Fire-and-forget init (audioInit().catchError(...)) hides failures; add a timeout and tell
the user when a subsystem is unavailable.
- Watch list from the same research: Dart macros were canceled (Jan 2025) in favor of
augmentations; primary constructors are coming; WASM is becoming the default web target.
See also
- Flutter web (renderers, SEO, performance, when not to use it)
- go_router navigation patterns and opening your own links in-app
- Modern professional web design conventions (2026 snapshot)
- Flame engine architecture and gotchas