MustafaKucukcoskun/Refine-agent-kit / shared/.agent/skills/flutter-patterns
flutter-patterns
UnverifiedFlutter architecture and UI patterns with Riverpod, GoRouter, Dart 3 features, and testing practices.
Flutter Patterns Skill
1. Architecture and State Management (Riverpod 2.x)
- In modern Flutter, use
@riverpodannotation,Notifier(synchronous) andAsyncNotifier(asynchronous) classes instead of StateNotifier etc. - Prefer
ConsumerWidgetin widgets, orHookConsumerWidgetif using Hooks. - Provider Reading Criteria:
- To watch (trigger rebuilds):
ref.watch(provider)(only insidebuildmethod). - To call (event handlers):
ref.read(provider.notifier).methodName(). - To listen (show snackbar etc.):
ref.listen(provider, (prev, next) => ...).
- To watch (trigger rebuilds):
2. Navigation (GoRouter)
- Use
GoRouterfor declarative routing instead of classicNavigator.push. This approach automatically handles deep-linking. - Prefer
ShellRoutestructure for nested routing and bottom navigation bar. - Pass parameters using
pathParametersandextra(only for carrying objects when web URLs are not a concern).
3. Dart 3.x Features (Pattern Matching & Records)
- Do not create unnecessary classes to return two or three values; use Records:
(int code, String msg) fetch() { return (200, "OK"); }. Reading the result:var (code, msg) = fetch(); - Replace traditional if-else blocks or if cascades with Pattern Matching (
switchexpressions andcaseconditions). - Create union types with sealed classes (e.g., Result<Success, Failure>). Enforces exhaustiveness in
switch(all cases must be handled).
4. Layout and UI Principles
- To prevent infinite size errors (
hasBoundedHeightexception), pay attention toExpandedorFlexibleusage in columns inside lists/SingleChildScrollView. Avoid usingshrinkWrap: trueandphysics: NeverScrollableScrollPhysics()when nesting lists in a ScrollView — this is a performance disaster. Use Slivers (CustomScrollView,SliverList) instead. - When splitting into single-responsibility small widgets, prefer defining new StatelessWidget classes over extracting methods (methods returning Widget). This allows Flutter to better optimize the element tree and enables const constructor usage.
- Always call statically positioned widgets whose parameters do not change with the
constkeyword.
5. Testing
- For UI testing, use
flutter testwithWidgetTesterto isolate widgets, andtester.pumpWidgetfollowed bytester.pumpAndSettle(waits for all animations to finish) for rendering. - For mocking needs (e.g., Dio, SharedPreferences), prefer the
mocktailpackage over standardmockitoas it works perfectly with null-safety (no code generation required).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 318k | Updated | Claude CodeCodex | Unverified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 318k | Updated | Claude CodeCodex | Unverified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 318k | Updated | Claude CodeCodex | Unverified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |