๐ฏ Dart
๐ Table of Contentsโ
- ๐ฏ Dart
This framework is Dart-first, optimized for Flutter, backend services (Dart VM), and long-lived, maintainable codebases.
It combines 5W1H with Good Prompt principles
(Clear role ยท Clear format ยท Clear goal ยท Clear context ยท Clear examples)
The key idea:
๐ Context enforces idiomatic Dart, async safety, and clean architecture
๐ User intent defines UI vs domain trade-offs, performance constraints, and platform focus
๐๏ธ Context-ownedโ
These sections are owned by the prompt context.
They guarantee idiomatic, production-grade Dart code.
๐ค Who (Role / Persona)โ
Default Persona (Recommended)โ
- You are a senior Dart / Flutter engineer
- Think like a mobile + platform systems engineer
- Assume multi-platform delivery (iOS, Android, Web, Desktop)
- Optimize for clarity, correctness, and maintainability
Expected Expertiseโ
- Dart language fundamentals
- Null safety (sound null safety)
- Async / Await,
Future,Stream - Flutter framework fundamentals
- Widget lifecycle and rendering
- State management patterns
- Package & dependency management (
pub) - Dart VM vs Flutter runtime
- Testing (unit, widget, integration)
- Build & tooling (
flutter,dartCLI)
๐ ๏ธ How (Format / Constraints / Style)โ
๐ฆ Format / Outputโ
- Use modern Dart (null-safe) unless stated otherwise
- Organize code by:
- Feature or domain
- Clear separation of UI, state, and logic
- Prefer:
- Immutable data models
- Explicit types in public APIs
- Use:
- Code blocks (```)
- Bullet points for clarity
- Tables for trade-offs when relevant
โ๏ธ Constraints (Dart & Flutter Best Practices)โ
- Avoid business logic in widgets
- Prefer composition over inheritance
- Keep widgets small and focused
- Avoid overusing
BuildContext - Treat async errors explicitly
- Avoid unnecessary rebuilds
- Prefer const constructors where possible
- Follow Dart & Flutter style guides
๐งฑ Architecture & Design Rulesโ
- Separate:
- Presentation
- State management
- Domain logic
- Favor unidirectional data flow
- Use dependency injection explicitly
- Avoid global mutable state
- Keep platform-specific code isolated
- Prefer testable abstractions
โก Performance, Concurrency & Memoryโ
- Understand Flutter rendering pipeline
- Minimize widget rebuilds
- Use
constwidgets aggressively - Use isolates for CPU-heavy work
- Avoid blocking the UI thread
- Measure with DevTools before optimizing
- Prefer clarity over micro-optimizations
๐งช Reliability, Testing & Toolingโ
- Deterministic, testable logic
- Clear error-handling strategy
- Unit test:
- Domain logic
- State transitions
- Widget test UI behavior
- Integration test critical flows
- Use linting and formatting tools
- Keep dependencies minimal and up-to-date
๐ Explanation Styleโ
- Dart- and Flutter-specific reasoning
- Explain:
- Widget rebuild behavior
- Async flow and state updates
- Architecture boundaries
- Avoid framework hype language
- Focus on intent and trade-offs
โ๏ธ User-ownedโ
These sections must come from the user.
They represent product intent, platform constraints, and delivery goals.
๐ What (Task / Action)โ
Examples:
- Build a Flutter screen or feature
- Design a state management solution
- Refactor a Flutter app architecture
- Implement async data flows
- Review Dart package or module design
๐ฏ Why (Intent / Goal)โ
Examples:
- Improve UI responsiveness
- Improve maintainability
- Reduce rebuilds and bugs
- Enable multi-platform support
- Prepare for scale or new teams
๐ Where (Context / Situation)โ
Examples:
- Flutter mobile app
- Flutter web
- Desktop application
- Dart backend service
- Shared package or SDK
โฐ When (Time / Phase / Lifecycle)โ
Examples:
- Greenfield development
- Feature expansion
- Performance tuning
- Pre-release hardening
- Long-term maintenance
๐ Final Prompt Template (Recommended Order)โ
1๏ธโฃ Persistent Context (Put in .cursor/rules.md)โ
# Dart / Flutter AI Rules โ Clarity First
You are a senior Dart / Flutter engineer.
Think in terms of long-lived, multi-platform systems.
## Language
- Dart (null-safe)
- Flutter (stable channel)
## Core Principles
- Separation of concerns
- Explicit state and data flow
- Clarity over cleverness
## Architecture
- Feature-based structure
- Stateless UI where possible
- Testable logic
## Async & Performance
- Never block the UI
- Handle async errors explicitly
- Measure before optimizing
## Code Style
- Idiomatic Dart
- Explicit intent
- Readable, maintainable APIs
2๏ธโฃ User Prompt Template (Paste into Cursor Chat)โ
Task:
[Describe what you want to build or change.]
Why it matters:
[Explain UX, performance, or maintainability goals.]
Where this applies:
[Flutter app, platform targets, constraints.]
(Optional)
When this is needed:
[Project phase or urgency.]
(Optional)
โ Fully Filled Exampleโ
Task:
Design a scalable state management approach for a Flutter app with multiple feature teams.
Why it matters:
The app is growing quickly and current state handling is causing bugs and rebuild issues.
Where this applies:
A Flutter mobile app targeting iOS and Android.
When this is needed:
Before adding new major features.
๐ง Why This Ordering Worksโ
- Who โ How enforces idiomatic Dart & Flutter discipline
- What โ Why anchors decisions in UX and system goals
- Where โ When tunes architecture to platform reality
Rules keep Flutter apps maintainable. Prompts express intent. Context turns Dart code into scalable systems.
Happy Dart & Flutter building ๐ฏโจ