📁 Agents
Cursor Rules for Flutter: Project .mdc Rule Set Generator
Generate Cursor rules for a Flutter app from your real pubspec and folder layout: scoped .mdc files for widgets, state, routing, tests, and generated code.
0Reviews
Prompt
Act as a senior Flutter engineer who writes Cursor project rules (.mdc files in .cursor/rules) for Flutter and Dart codebases, so the Cursor agent follows the team's real architecture instead of generic Flutter habits. Inputs: - pubspec.yaml dependencies and dev_dependencies, pasted as is: [Pubspec] - analysis_options.yaml, pasted as is: [AnalysisOptions] - Folder structure of lib/ and test/ two levels deep: [FolderTree] - State management, routing, and data layer the app actually uses (for example Riverpod, Bloc, Provider; go_router; Dio, http, Drift): [ArchitectureChoices] - Code generation in use (freezed, json_serializable, build_runner) and which files are generated: [Codegen] - Team conventions that are not written down anywhere yet: [Conventions] - Things the agent keeps getting wrong in this repo: [AgentMistakes] - Output format: [Format] Generate: 1. An evidence check: list every package and convention you will reference and where it came from (Pubspec, AnalysisOptions, FolderTree, or my notes). Anything not found is left out of the rules, not guessed. 2. A rule plan: a table of 5 to 7 .mdc files with file name, rule type (always apply, auto attached by globs, agent requested by description, or manual), globs, and a one line purpose. 3. The always apply core rule (under 40 lines): project summary, folder map from FolderTree, the commands to run after edits (flutter analyze, dart format, flutter test) and the build_runner command if Codegen uses it. 4. A widgets rule scoped to the UI folders: composition over deep widget trees, const constructors where possible, no business logic in build methods, and context use after await only behind a mounted check. 5. A state management rule written for the exact library in ArchitectureChoices, with the file naming and provider or bloc placement used in FolderTree. 6. A routing and navigation rule for the routing package in Pubspec, or skip it if there is none. 7. A data and models rule that covers Codegen: never hand edit generated files, regenerate after model changes, and where models and repositories live. 8. A testing rule scoped to test/: where tests go, naming, which test types the repo uses, and what to mock. 9. A rule for AgentMistakes: each mistake turned into a short do and do not pair. 10. Full .mdc file contents for every rule with front matter (description, globs, alwaysApply), ready to save. Constraints: - Only reference packages present in Pubspec and lints present in AnalysisOptions. - Keep each rule short and specific; no generic Dart style guide filler. - Do not invent folder paths; use FolderTree exactly. - No em dashes.
Instructions
Run this in Cursor's chat (Ask or Agent mode) with your pubspec.yaml and analysis_options.yaml pasted or attached. Replace every [bracket] with your details.
Generated Output
This image was generated using the prompt above.

Examples
Example Input
Pubspec: dependencies: flutter, flutter_riverpod 2.x, riverpod_annotation, go_router, dio, freezed_annotation, json_annotation, intl. dev_dependencies: flutter_test, flutter_lints, build_runner, riverpod_generator, freezed, json_serializable, mocktail.
AnalysisOptions: include: package:flutter_lints/flutter.yaml. Extra rules: prefer_const_constructors, avoid_print, use_build_context_synchronously.
FolderTree: lib/app/ (router.dart, theme.dart), lib/features/orders/{data,domain,presentation}, lib/features/auth/{data,domain,presentation}, lib/shared/widgets/. test/features/orders/, test/features/auth/.
ArchitectureChoices: Riverpod with code generation (@riverpod), go_router with typed routes in lib/app/router.dart, Dio client in lib/shared/api_client.dart, repositories in each feature's data folder.
Codegen: freezed and json_serializable for models in domain/, riverpod_generator for providers. Generated files end in .g.dart and .freezed.dart.
Conventions: One feature per folder. Screens end in _screen.dart, widgets in _widget.dart. No setState outside lib/shared/widgets/.
AgentMistakes: Edits .g.dart files by hand. Uses Navigator.push instead of go_router. Puts API calls inside widgets.
Format: rule plan table, then each fileExample Output
1. EVIDENCE
Packages: flutter_riverpod, riverpod_annotation, riverpod_generator, go_router, dio, freezed, json_serializable, mocktail, intl (Pubspec). Lints: flutter_lints plus prefer_const_constructors, avoid_print, use_build_context_synchronously (AnalysisOptions). Folders from FolderTree. Naming and setState rule from Conventions.
2. RULE PLAN
| File | Type | Globs | Purpose |
| 00-core.mdc | always apply | | Map, commands |
| widgets.mdc | auto attached | lib/**/presentation/**, lib/shared/widgets/** | UI rules |
| riverpod.mdc | auto attached | lib/**/*_provider.dart, lib/**/presentation/** | State |
| routing.mdc | auto attached | lib/app/router.dart, lib/**/presentation/** | go_router only |
| models-codegen.mdc | auto attached | lib/**/domain/**, lib/**/data/** | freezed, repos |
| testing.mdc | auto attached | test/** | Tests, mocktail |
3. 00-core.mdc
---
description: Core project map and commands
alwaysApply: true
---
- Flutter app, feature first: lib/features/{feature}/{data,domain,presentation}.
- App wiring in lib/app/ (router.dart, theme.dart). Shared widgets in lib/shared/widgets/. API client in lib/shared/api_client.dart.
- After edits run: flutter analyze, dart format ., flutter test.
- After changing a model or provider run: dart run build_runner build --delete-conflicting-outputs.
4. widgets.mdc
---
description: Widget and screen rules
globs: lib/**/presentation/**, lib/shared/widgets/**
alwaysApply: false
---
- Screens end in _screen.dart, widgets in _widget.dart.
- Use const constructors where possible (prefer_const_constructors is on).
- No API calls or repository calls in widgets; read state through providers.
- setState only inside lib/shared/widgets/.
- After await, check context.mounted before using context.
5. riverpod.mdc
- Use @riverpod code generation; do not write providers by hand.
- Providers live next to their feature in presentation/ or data/.
6. routing.mdc
- Navigate only with go_router (context.go, context.push). Never Navigator.push.
- Add routes in lib/app/router.dart.
7. models-codegen.mdc
- Models in domain/ use freezed and json_serializable.
- Never edit .g.dart or .freezed.dart files. Change the source and rerun build_runner.
- Repositories in data/ wrap the Dio client.
8. testing.mdc
- Mirror lib paths under test/features/.
- Mock repositories with mocktail; never call the real API in tests.
9. AGENT MISTAKES (in core and scoped rules)
Do: change the source model and run build_runner. Do not: edit generated files.
Do: use go_router. Do not: use Navigator.push.
Do: call APIs in repositories. Do not: call Dio from widgets.
10. Save each block as .cursor/rules/[file].mdc.