Skip to content
Back to skills

Flutter Rules

ASecurity

Standing rules for Flutter code covering widget composition, const constructors, a single state management approach, async and BuildContext safety, theming, accessibility and widget tests.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 26, 2026
ai-agentsgonodeperformance

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 26, 2026

npx -y skills add hermes-hq/hodios-dist --skill flutter-rules --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Flutter Rules?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Flutter Rules
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hermes-hq-flutter-rules/badge)](https://www.skillsdirectory.com/skills/hermes-hq-flutter-rules)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: flutter-rules
description: Standing rules for Flutter code covering widget composition, const constructors, a single state management approach, async and BuildContext safety, theming, accessibility and widget tests.
license: CC0-1.0
metadata:
  version: 1.0.0
  kind: rule
  category: conventions
  source: https://hermes-ide.com/prompts/flutter-rules
  catalog: 2026.1014.1
---

# Flutter rules

Apply these rules to files matching: `lib/**/*.dart`, `test/**/*.dart`, `integration_test/**/*.dart`.

When you write or change code in this Flutter app:

**Know the project first**
- Check `pubspec.yaml` for the Flutter and Dart SDK constraints and the packages already in use (state management, routing, HTTP, code generation), and follow the patterns in existing features. Do not add a package for something the project already does another way.

**Widget composition**
- Split large `build` methods into small widget classes, not helper methods that return widgets. Separate classes rebuild independently and can be `const`.
- Mark widget constructors and widget instances `const` whenever their inputs are compile-time constants, and keep the `prefer_const_constructors` lints passing.
- Keep `build` pure and cheap: no network calls, no object creation that should persist, no side effects. Create controllers, streams and futures in `initState` (or the state management layer), never in `build`.
- Give widgets in reorderable or dynamic lists stable `Key`s derived from the data.

**State management**
- Use the one state management approach the project already uses (for example Provider, Riverpod, Bloc or plain `ValueNotifier`). Do not introduce a second one. If the project has none and the feature needs shared state, ask before choosing.
- Keep business logic and I/O out of widgets: widgets read state and dispatch intents; repositories and services talk to the network and storage.
- Use `setState` only for state local to one widget, and call it only while the widget is mounted.

**Async and BuildContext safety**
- After any `await` in a widget or state method, check `if (!context.mounted) return;` (or `mounted` in a `State`) before using `context`, calling `setState` or navigating.
- Dispose every `TextEditingController`, `AnimationController`, `ScrollController`, `FocusNode`, stream subscription and timer you create, in `dispose()`.
- Show loading, error and empty states for every asynchronous view; never leave a spinner with no timeout or error path.

**Lists and performance**
- Use `ListView.builder`, `GridView.builder` or slivers for long or unbounded lists, never a `Column` inside a `SingleChildScrollView` with hundreds of children.
- Size images to their display size and cache network images with the project's approach. Profile in profile mode, not debug, before claiming a performance fix.

**Theming and layout**
- Take colours, text styles and shapes from `Theme.of(context)` (`colorScheme`, `textTheme`) or the project's design tokens. Do not hard-code colours or font sizes in widgets, and support dark mode if the app does.
- Build layouts that adapt to screen size and text scale with `LayoutBuilder`, `MediaQuery` or flexible widgets, not fixed pixel widths. Test with large text scaling.
- Respect safe areas and the keyboard (`SafeArea`, scrollable forms).

**Accessibility**
- Give icon-only buttons a `tooltip` or semantic label, and images a `semanticLabel` (or exclude decorative ones from semantics).
- Keep tap targets at least 48 by 48 logical pixels and colour contrast at WCAG AA. Do not convey meaning by colour alone.
- Make custom controls expose their role and state through `Semantics`.

**Strings**
- Put user-facing text in the project's localisation files if it has them, never inline in widgets.

**Tests**
- Add widget tests with `testWidgets` and `pumpWidget` for new screens and components, finding widgets by key, text or semantics label, and covering loading, error and data states. Unit test the logic layer without widgets.
- Before finishing, run `flutter analyze` and `flutter test`, and fix every analyzer warning you introduced.

Files in this skill

  • SKILL.md4 KB
  • agents/openai.yaml294 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.