Skip to content

project rulesMobileflutterdart

Flutter Rules

Project rules for Flutter apps: feature folders, one state solution, const widgets, ThemeData tokens and widget and unit tests.

npx workspacetemplates add flutter-rules --tool claude-code

Writes 1 file to your project root

CLAUDE.mdadd to your file21 lines · 1.2 KBFile
# Project rules: Flutter

## Layout
- Organize by feature: `lib/features/<name>/{data,domain,presentation}`, with shared code in `lib/core`. Keep `main.dart` to bootstrapping.
- Enable `flutter_lints` or stricter in `analysis_options.yaml` and fix every warning.

## State
- Choose one solution per app (Riverpod or Bloc) and use it everywhere. Keep `setState` for purely local, ephemeral UI state.
- State classes are immutable. Widgets read state and call methods; they do not call repositories or HTTP directly.

## Widgets
- Prefer small widget classes over helper methods returning widgets. Mark constructors and literals `const`.
- Use `ListView.builder` for long lists, give items keys when order changes, and dispose controllers, focus nodes and subscriptions.
- Never use `BuildContext` after an `await` without checking `mounted`.

## Theming and text
- Define colors, typography and spacing in `ThemeData` and extensions; read them via `Theme.of(context)`. Put user-facing strings in localization files.

## Quality
- Write unit tests for logic and widget tests with `pumpWidget` for screens. Use golden tests sparingly.
- Run `dart format --set-exit-if-changed .`, `flutter analyze` and `flutter test` before finishing.

What it does

These rules give a Flutter project a predictable layout and a single way to manage state, so an agent adds features without inventing a new pattern each time.

They focus on practices that keep frames smooth and code reviewable: const constructors, small widgets, centralized theming and tests that pump real widgets.

Example

you › Add a favorites tab that persists across launches

agent › The agent adds a favorites feature folder, a Riverpod notifier with local storage, const widgets using theme tokens and a widget test for toggling.

Questions

Why only one state package?
Mixed approaches make every feature a new reading exercise and invite sync bugs between them.
Are golden tests required?
No. They are allowed for stable, visual components but are not a default.
  • Kotlin Android Rules

    Project ruleskotlin

    Free
  • React Native Expo Rules

    Project rulesreact-native

    Free
  • SwiftUI iOS Rules

    Project rulesswift

    Free
  • Flutter State Management

    Skillflutter

    Free