flutter-conventions
Skill2 starsChanged 41 days agoMITView on GitHub
Conventions and proven patterns for Flutter apps built with Riverpod, flutter_hooks and auto_route. Use when implementing or changing Flutter code.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- Tenraining/Claude-Skillstheir own version, first seen Nov 1, 2026
- techmefr/mentistheir own version, first seen Sep 11, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- Tenraining/Claude-Skills★ 1same name
- techmefr/mentis★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- flutter-capture-patternSkill
- flutter-code-qualitySkill
- flutter-testingSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 30
Before creating a widget, look in lib/common/widgets/ and the feature's widgets/.
- Very specific: line 53
Use the newest syntax the project's SDK constraint allows (environment: sdk: in pubspec.yaml):
- Very specific: line 91
Run code generation after changing providers, routes or serialisable models, then dart analyze (through fvm when the project uses it).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Flutter Conventions
How this family of apps is built. The rules below apply to every change; the references/ files hold the shapes for specific tasks and are read when the task touches them. Project AGENTS.md files add project-specific facts (commands, backend, branding) and override anything here when they conflict.
Stack: Flutter stable, Riverpod 3 with code generation, flutter_hooks, auto_route, easy_localization, Equatable, package:collection, package:logging, Lucide icons. Backends vary (gRPC, REST over Dio, Firebase); the layering does not.
Architecture
Three layers, one direction of dependency:
API (domain/) → Provider (provider/) → UI (screens, widgets/)- The API class talks to the backend and returns domain entities. Transport types (proto messages, JSON maps, Firestore snapshots) are converted in the API class via extension methods colocated with the entity and never leave
domain/. - Providers own state and orchestrate API calls. Business rules live in entity computed properties (
bool get canDelete => isOwner && !isArchived), not in widgets or providers. - UI reads providers and triggers notifier methods. It never calls an API or touches storage directly.
These three boundaries are the invariants of the codebase. Everything else in this file is a default to follow unless the project says otherwise.
Project Structure
Feature folders directly under lib/ (lib/account/, lib/payment/), screens at the feature root, and domain/, provider/, widgets/ subfolders created when two or more files justify them. Shared code lives in lib/common/ (widgets/, extensions/, util/, theme/, storage/, data/). No features/ wrapper, no presentation/ layer, no barrel files. Details: references/folder_structure.md.
Before creating a widget, look in lib/common/widgets/ and the feature's widgets/; reuse beats a near-duplicate.
Widgets
- Screens are
HookConsumerWidget; smaller widgets areHookWidgetorStatelessWidget.StatefulWidgetonly when a hook cannot express the lifecycle. - Inside
build(): providers, then hooks, then derived values, then widget variables in render order. Always-shown subtrees are local variables, conditional ones are_buildX()methods, large or reused or stateful ones are their own widget in their own file. No file-private widget classes. - Helpers needing four or more locals (hooks, controllers) are closures inside
build(); otherwise class methods. PassWidgetRefalone when a helper needs both ref and context (ref.context). - Styling comes from
context.color,context.typographyand the spacing constants (kGapItem,kGapSection,kSide,kCorner); icons fromLucideIcons. No hex literals or magic numbers in widgets. - Shared widgets (
AppPrimaryButton,AppBottomSheet,AppTextField,AppChip) are written inlib/common/widgets/on top of Material widgets and the theme tokens. No third-party component kit; the app owns its design system.
Details: references/widget_style_guide.md, references/hooks.md, references/design_principles.md.
State and Actions
- Data that outlives a screen lives in a provider; a widget keeps only ephemeral UI state (focus, a local toggle) in hooks.
- Each user action is an on-demand action provider (
FutureOr<T?> build() => null) whose method usesAsyncValue.guard, checksref.mountedbefore writingstateafter an await, and invalidates the providers it made stale. The action'sisLoadingdrives the button; the screen reacts to the outcome throughref.listen/ref.listenOnError. - First-load errors render inline with a retry that invalidates the provider. Action errors show a toast via
listenOnErrorand the user retries by tapping again. Refreshes keep existing content visible. - Complex state is a sealed type switched exhaustively, never a set of booleans.
Details: references/riverpod.md, references/error_handling.md.
Modern Dart
Use the newest syntax the project's SDK constraint allows (environment: sdk: in pubspec.yaml):
- Switch expressions, records, patterns and sealed classes (Dart 3.0+).
Column(spacing:)/Row(spacing:)(Flutter 3.27+) when every gap is equal;.divide(widget)when the separator is a real widget or the children are inline spans.- Dot shorthands (
alignment: .center,padding: .all(16)) when the type is inferred (Dart 3.10+). - Primary constructors where the SDK and lints accept them.
package:collectionhelpers (sorted,firstWhereOrNull,groupBy) over manual loops and mutation.
Where to Look
| Task touches | Read |
| New feature's API, entity, DTO | references/rest_api.md (REST and gRPC variant) |
| Providers, families, lifecycle, mutations | references/riverpod.md |
| Exceptions, error display, crash reporting | references/error_handling.md |
| Screen layout, extraction, build order | references/widget_style_guide.md |
| Hooks, controllers, StatefulWidget migration | references/hooks.md |
| State modelling, widget APIs, abstraction decisions | references/design_principles.md |
| Lists, pagination, skeletons, empty and error states | references/lists.md |
| Filters, sorting, filter sheets | references/filter_sort.md |
| Client-side search | references/entity_search.md |
| Forms, validation, submit | references/forms.md |
| Bottom sheets, dialogs, confirmations | references/sheets_dialogs.md |
| Multi-step flows, drafts | references/wizard.md |
| Routes, tabs, deep-linkable screens, typed results | references/navigation.md |
| App entry, flavors, container | references/app_bootstrap.md |
| Log levels, what to log where, transport logging, crash reporter routing | references/logging.md |
| Splash, startup checks, forced update | references/startup_gate.md |
| Auth state, sign-out, account selection | references/auth_session.md |
| Analytics, support, purchases or push SDK wrappers | references/sdk_session.md |
| Preferences, secure storage, caches | references/storage.md |
| Translations and the codegen script | references/localization.md |
| Colors, typography, dark mode | references/theme.md |
| Shared extensions and hooks a new app needs | references/common_kit.md |
| Lint setup for a new project | references/analysis_options.yaml |
Finishing
Run code generation after changing providers, routes or serialisable models, then dart analyze (through fvm when the project uses it). Before reporting a Flutter change as done, run the flutter-code-quality check on the changed files and apply its findings.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

