Flutter + Dart Rules
Cursor rules for Flutter + Dart projects. Widget patterns, state management, naming, and error handling conventions.
What it does
These Cursor rules teach Cursor how to generate Flutter code that matches production team conventions: trailing commas, const everywhere, StatelessWidget first, hooks_riverpod for state, snake_case file names, and a features-folder architecture. Drop the file at your project root and Cursor respects them in every Cmd+K and Cmd+L session.
What it solves
Cursor without project-specific rules generates Flutter code that technically works but does not match your team's style. You end up reformatting every output. These rules put an end to that loop.
How to install
Which tool are you using?
Not sure? Claude.ai is the website. Claude Code is the command-line tool you install separately. Cursor is a code editor that reads .cursorrules.
- 01
Open your project in Cursor
Open Cursor (the code editor) and make sure your project folder is open. You should see your project files in the left sidebar.
Don't have Cursor? Download it free at cursor.com
- 02
Look at your project files
In the left sidebar, look for a file called '.cursorrules' in the root of your project (same level as pubspec.yaml or package.json).
If you see .cursorrules already, you can replace its contents or add to it.
- 03
Create the .cursorrules file
If .cursorrules doesn't exist: Right-click in the file explorer sidebar → click 'New File' → type exactly: .cursorrules (including the dot at the start) → press Enter.
The dot at the start is important. The filename must be exactly '.cursorrules' with nothing else.
- 04
Copy the rules below
Scroll down to the rules file section below and click 'Copy'. All the rules will be copied to your clipboard.
- 05
Paste and save
Click inside the .cursorrules file, press Ctrl+A (Windows) or Cmd+A (Mac) to select all, then paste with Ctrl+V or Cmd+V. Press Ctrl+S or Cmd+S to save.
You're done! Cursor reads this file automatically. Every AI response in this project will now follow these rules.
The cursor rules file
Copy the full contents below, or download the file directly.
# Flutter + Dart Cursor Rules You are an expert Flutter developer. Follow these rules: ## Code Style- Use trailing commas in all multi-line parameter lists- Prefer const constructors everywhere possible- Use named parameters for functions with 2+ params- Keep files under 200 lines — split if longer ## Widget Rules- Every screen is a separate file in screens/- Extract any widget used more than once to widgets/- StatelessWidget first — only use Stateful when needed- Use hooks_riverpod for state in new code ## Naming- Screens: LoginScreen, HomeScreen (PascalCase + Screen)- Widgets: PrimaryButton, UserCard (PascalCase, descriptive)- Providers: userProvider, authStateProvider (camelCase + Provider)- Files: login_screen.dart, primary_button.dart (snake_case) ## Architecture- Features folder per domain (auth, profile, feed)- Each feature: data / domain / presentation layers- Repositories abstract all data sources- Never call API directly from widgets ## Error Handling- Always handle loading, error, and empty states- Use AsyncValue from Riverpod for async state- Show SnackBar for transient errors- Show error widget for page-level failures ## Performance- ListView.builder for any list that could exceed 10 items- Cache network images with cached_network_image- Use const for all widgets that don't depend on runtime valuesExample output
What Claude does before and after you install this cursor rules.
Cursor generates a LoginPage.dart (wrong case), uses setState for auth state, and skips const on everything. You reformat for 5 minutes.
Cursor generates login_screen.dart with an authStateProvider, proper AsyncValue handling, const constructors, and SnackBar error handling. Ship it.
Customization tips
Edit the State Management section if your team uses Bloc or GetX instead of Riverpod. If you keep all screens in a flat structure instead of features folders, swap the Architecture section. Teams with strict test coverage rules can add a 'Testing' section requiring test files per widget.
Related resources
Flutter Development Skill
Teaches Claude Flutter best practices, widget patterns, state management conventions, and your team's coding style.
Flutter Widget Architect
Designs Flutter widget trees with proper separation of concerns and state management.
React Native Rules
Cursor rules for React Native projects. Navigation, performance, platform handling, and testing conventions.
Frequently asked questions
What's the difference between .cursorrules and a Claude Skill?
.cursorrules works inside the Cursor editor and applies to every AI interaction in that project. Claude Skills work in Claude Code (the terminal tool). If you use Cursor, use .cursorrules. If you use Claude Code, use the skill file.
Do I need a new .cursorrules for every project?
Yes — .cursorrules is per-project because different projects have different conventions. Copy this file into each Flutter project's root folder.
My team has different conventions — how do I customize this?
Open .cursorrules in any text editor. Edit the sections that don't match your team. For example, if you use GetX instead of Riverpod, change the State Management section. The file is plain text — no special format needed.
Will this slow down Cursor?
No. Cursor reads the file once when you open the project. It adds context to AI requests but doesn't affect editor performance.
Can I combine this with a CLAUDE.md file?
Yes — they serve different purposes. .cursorrules guides Cursor's AI. CLAUDE.md guides Claude Code. If your team uses both tools, have both files in your project root.
Want more like this?
Browse the full RohanKit library — free resources for Claude and Cursor.