Dart · Flutter

Flutter rules for Cursor

Widget, state and async rules that keep generated Flutter code fast and crash-free.

The rule

Save as .cursor/rules/flutter.mdc. Cursor picks it up on the next request.

.cursor/rules/flutter.mdc

---
description: Flutter app conventions
globs: **/*.dart
alwaysApply: false
---

- Split UI into small widget classes, not helper methods that return widgets. Use const constructors wherever possible.
- Use the project's existing state management; do not introduce a new one.
- Dispose controllers, focus nodes, animation controllers and stream subscriptions in dispose().
- After an await, check context.mounted (or mounted in a State) before using BuildContext.
- Use ListView.builder or other builder constructors for long or dynamic lists.
- Take colors and text styles from Theme.of(context) instead of hard-coding them.
- Use Color.withValues(alpha: ...) instead of the deprecated withOpacity.
- Add packages with flutter pub add, not by hand-editing version numbers.
- Run dart format, flutter analyze and flutter test before finishing.

How Cursor loads this rule

Read from the frontmatter above, per Cursor's rules documentation.

  • alwaysApply: false with globs: **/*.dart: attached automatically when a matching file is in context.
  • Keep the .mdc extension. A plain .md file in .cursor/rules is ignored by the rules system.
  • Prefer to generate your own? Type /create-rule in Agent and describe what you want; Cursor saves the file to .cursor/rules.
  • Team Rules come first, then Project Rules like this one, then User Rules. Earlier sources win when guidance conflicts.

Cursor rules setup guideCursor Team RulesLet Cursor run commands without asking

Flutter rules for Claude Code, Copilot, Kiro and other agents

The same instructions work as plain Markdown in AGENTS.md, which Codex, Gemini CLI, GitHub Copilot and most other coding agents read.

AGENTS.md (section)

## Flutter

- Split UI into small widget classes, not helper methods that return widgets. Use const constructors wherever possible.
- Use the project's existing state management; do not introduce a new one.
- Dispose controllers, focus nodes, animation controllers and stream subscriptions in dispose().
- After an await, check context.mounted (or mounted in a State) before using BuildContext.
- Use ListView.builder or other builder constructors for long or dynamic lists.
- Take colors and text styles from Theme.of(context) instead of hard-coding them.
- Use Color.withValues(alpha: ...) instead of the deprecated withOpacity.
- Add packages with flutter pub add, not by hand-editing version numbers.
- Run dart format, flutter analyze and flutter test before finishing.
Flutter rules for Claude Code.claude/rules/flutter.md

.claude/rules/flutter.md

---
paths:
  - "**/*.dart"
---

- Split UI into small widget classes, not helper methods that return widgets. Use const constructors wherever possible.
- Use the project's existing state management; do not introduce a new one.
- Dispose controllers, focus nodes, animation controllers and stream subscriptions in dispose().
- After an await, check context.mounted (or mounted in a State) before using BuildContext.
- Use ListView.builder or other builder constructors for long or dynamic lists.
- Take colors and text styles from Theme.of(context) instead of hard-coding them.
- Use Color.withValues(alpha: ...) instead of the deprecated withOpacity.
- Add packages with flutter pub add, not by hand-editing version numbers.
- Run dart format, flutter analyze and flutter test before finishing.
Flutter rules for GitHub Copilot.github/instructions/flutter.instructions.md

.github/instructions/flutter.instructions.md

---
applyTo: "**/*.dart"
---

- Split UI into small widget classes, not helper methods that return widgets. Use const constructors wherever possible.
- Use the project's existing state management; do not introduce a new one.
- Dispose controllers, focus nodes, animation controllers and stream subscriptions in dispose().
- After an await, check context.mounted (or mounted in a State) before using BuildContext.
- Use ListView.builder or other builder constructors for long or dynamic lists.
- Take colors and text styles from Theme.of(context) instead of hard-coding them.
- Use Color.withValues(alpha: ...) instead of the deprecated withOpacity.
- Add packages with flutter pub add, not by hand-editing version numbers.
- Run dart format, flutter analyze and flutter test before finishing.
Flutter rules for Kiro.kiro/steering/flutter.md

.kiro/steering/flutter.md

---
inclusion: fileMatch
fileMatchPattern: ["**/*.dart"]
---

- Split UI into small widget classes, not helper methods that return widgets. Use const constructors wherever possible.
- Use the project's existing state management; do not introduce a new one.
- Dispose controllers, focus nodes, animation controllers and stream subscriptions in dispose().
- After an await, check context.mounted (or mounted in a State) before using BuildContext.
- Use ListView.builder or other builder constructors for long or dynamic lists.
- Take colors and text styles from Theme.of(context) instead of hard-coding them.
- Use Color.withValues(alpha: ...) instead of the deprecated withOpacity.
- Add packages with flutter pub add, not by hand-editing version numbers.
- Run dart format, flutter analyze and flutter test before finishing.
Flutter rules for Antigravity.agents/rules/flutter.md

.agents/rules/flutter.md

---
trigger: glob
globs: "**/*.dart"
---

- Split UI into small widget classes, not helper methods that return widgets. Use const constructors wherever possible.
- Use the project's existing state management; do not introduce a new one.
- Dispose controllers, focus nodes, animation controllers and stream subscriptions in dispose().
- After an await, check context.mounted (or mounted in a State) before using BuildContext.
- Use ListView.builder or other builder constructors for long or dynamic lists.
- Take colors and text styles from Theme.of(context) instead of hard-coding them.
- Use Color.withValues(alpha: ...) instead of the deprecated withOpacity.
- Add packages with flutter pub add, not by hand-editing version numbers.
- Run dart format, flutter analyze and flutter test before finishing.
Flutter rules for Devin Desktop (Windsurf).devin/rules/flutter.md

.devin/rules/flutter.md

---
trigger: glob
globs: **/*.dart
---

- Split UI into small widget classes, not helper methods that return widgets. Use const constructors wherever possible.
- Use the project's existing state management; do not introduce a new one.
- Dispose controllers, focus nodes, animation controllers and stream subscriptions in dispose().
- After an await, check context.mounted (or mounted in a State) before using BuildContext.
- Use ListView.builder or other builder constructors for long or dynamic lists.
- Take colors and text styles from Theme.of(context) instead of hard-coding them.
- Use Color.withValues(alpha: ...) instead of the deprecated withOpacity.
- Add packages with flutter pub add, not by hand-editing version numbers.
- Run dart format, flutter analyze and flutter test before finishing.
Flutter rules for Cline.clinerules/flutter.md

.clinerules/flutter.md

---
paths:
  - "**/*.dart"
---

- Split UI into small widget classes, not helper methods that return widgets. Use const constructors wherever possible.
- Use the project's existing state management; do not introduce a new one.
- Dispose controllers, focus nodes, animation controllers and stream subscriptions in dispose().
- After an await, check context.mounted (or mounted in a State) before using BuildContext.
- Use ListView.builder or other builder constructors for long or dynamic lists.
- Take colors and text styles from Theme.of(context) instead of hard-coding them.
- Use Color.withValues(alpha: ...) instead of the deprecated withOpacity.
- Add packages with flutter pub add, not by hand-editing version numbers.
- Run dart format, flutter analyze and flutter test before finishing.
Flutter rules for Continue.continue/rules/flutter.md

.continue/rules/flutter.md

---
name: "flutter"
globs: ["**/*.dart"]
---

- Split UI into small widget classes, not helper methods that return widgets. Use const constructors wherever possible.
- Use the project's existing state management; do not introduce a new one.
- Dispose controllers, focus nodes, animation controllers and stream subscriptions in dispose().
- After an await, check context.mounted (or mounted in a State) before using BuildContext.
- Use ListView.builder or other builder constructors for long or dynamic lists.
- Take colors and text styles from Theme.of(context) instead of hard-coding them.
- Use Color.withValues(alpha: ...) instead of the deprecated withOpacity.
- Add packages with flutter pub add, not by hand-editing version numbers.
- Run dart format, flutter analyze and flutter test before finishing.

Edit this rule and convert it for 11 agents →

More templates

Get Cursor rules and settings changes by email

When Cursor changes how rules, run modes or settings work, we update these templates from the docs and send a short note. One email a week at most.

Reviewed Oct 20, 2026. Written by AgentAtlas. Adapt it to your codebase before relying on it.