Cursor Rules for Flutter: 10 .mdc Rule Prompts to Copy
Cursor rules for Flutter: 10 prompts that write scoped .mdc rules for widgets, Riverpod or Bloc, go_router, code generation, tests, and agent mistakes.

Good Cursor rules for Flutter are short, scoped, and based on your real project, not a generic Dart style guide. Put them in .cursor/rules as .mdc files, keep one small rule that always applies, and attach the rest by globs to the folders they govern. The 10 prompts below ask Cursor to write each rule from your pubspec.yaml, analysis_options.yaml, and folder tree, so the rules only mention packages you actually use.
Run them in Cursor's chat with those files attached. Review each rule before saving it, because a wrong rule repeats the same mistake in every session.
How Cursor project rules work
Each .mdc file starts with a short front matter block: a description, optional globs, and an alwaysApply flag. An always applied rule loads in every chat. A rule with globs attaches when matching files are involved. A rule with only a description can be pulled in by the agent when it looks relevant, and you can reference any rule by name manually. Keep the always applied rule small.
Prompts for the core rule
1. Project map and commands
From my folder tree [paste] and pubspec.yaml [paste], write an alwaysApply .mdc rule under 40 lines with the folder map and the commands to run after edits: flutter analyze, dart format, flutter test, and build_runner only if it is in dev_dependencies.
2. Evidence check before writing rules
List every package, lint, and folder you plan to mention in my Cursor rules and where you found it. Leave out anything you cannot find in the files I attached.
Prompts for app code
3. Widgets rule
Write a widgets.mdc rule with globs for [UI folders]. Cover const constructors, no API calls in widgets, splitting large build methods, my file naming [convention], and checking context.mounted after await.
4. State management rule
We use [Riverpod with code generation, Bloc, or Provider]. Write a state.mdc rule for that library only: where providers or blocs live in my tree, naming, and what not to do.
5. Routing rule
We use [go_router or auto_route] with routes in [file]. Write a routing.mdc rule that bans other navigation styles and says where new routes go.
6. Models and code generation rule
We use [freezed, json_serializable] and generated files end in [.g.dart, .freezed.dart]. Write a rule that forbids editing generated files and says when to run dart run build_runner build --delete-conflicting-outputs.
7. Data layer rule
Our API client is [file] using [dio or http], and repositories live in [folder]. Write a data.mdc rule so all network calls go through repositories and errors are mapped the way [describe] does it.
Prompts for tests and quality
8. Testing rule
Write a testing.mdc rule with globs for test/**. Mirror lib paths, use [mocktail or mockito] for mocks, never call the real API, and add a widget test for every new screen.
9. Lints from analysis_options
Here is my analysis_options.yaml: [paste]. Turn only the lints the agent tends to break into short rule lines, and tell me which ones flutter analyze already enforces so I do not repeat them.
10. Agent mistakes rule
The Cursor agent keeps doing these things in this repo: [list]. Turn each into a do and do not pair and tell me which rule file it belongs in.
Generate the whole rule set at once
The Cursor Rules for Flutter: Project .mdc Rule Set Generator runs all of these in one pass. It checks evidence, plans 5 to 7 rule files with types and globs, and writes full .mdc contents for the core, widgets, state, routing, models and codegen, and testing rules, plus a rule for the agent's repeat mistakes. The example builds rules for a feature first app using Riverpod code generation, go_router, Dio, and freezed.
Keep rules useful
- Update a rule when the agent makes the same mistake twice.
- Delete rules for packages you removed from pubspec.yaml.
- Prefer one line instructions over paragraphs.
Related prompts
For any stack, the Cursor Rules .mdc from a Repo Brief prompt is the general version, and the AGENTS.md plus Cursor .mdc Compiler keeps rules in sync across tools. Theming a Flutter app? Try the Material 3 Color Scheme Builder. Find more in the Agents prompts hub, browse more prompts, or share a prompt with your own Flutter rules.