Reduce complexity in Flutter/Dart code. Use when code is too nested, hard to read, or has duplication. Extracts widgets, flattens logic, removes unnecessary abstraction.
Principles and patterns for simplifying Flutter/Dart code. Simplification means making code easier to reason about — not making it shorter at the cost of clarity.
Clarity over brevity. Explicit code is often better than compact code. The goal is code that's easy to read, understand, and maintain without changing what it does.
Never change what the code does — only how it does it. All original features, outputs, and behaviors must remain intact.
Avoid over-simplification that could:
Use expertise to determine what improves the code. These principles guide decisions — they are not a checklist. If a change doesn't clearly improve clarity while preserving behavior, don't make it.
Common opportunities in Flutter/Dart code. Apply when they genuinely improve clarity.
| Pattern | Simplification |
|---------|----------------|
| Scattered boolean flags | Sealed class variants with switch expressions (when it consolidates and clarifies) |
| Same parameters repeated across functions | Records or typed classes |
| Manual try-catch in providers | AsyncValue.guard() with centralized error handling |
| Async operations without mount check | Check ref.mounted after async operations |
| Pattern | Simplification |
|---------|----------------|
| Large build() methods | Extract into local variables or builder methods |
| Widgets with many boolean parameters | Consider composition or typed mode objects |
| Unordered build() | Keep order: providers → hooks → derived values → widget tree |
| Pattern | Simplification |
|---------|----------------|
| Mutation patterns | Immutable methods (.sorted(), .where(), etc.) |
| Null-unsafe access | firstWhereOrNull with fallbacks |
| Repeated enum switches | Computed properties on the enum itself |
| Pattern | Simplification | |---------|----------------| | Duplicated logic across files | Extract to shared location | | Related methods scattered in class | Group by concern | | Unnecessary indirection (factories creating one type, wrappers adding no behavior) | Use concrete types directly |
Exception: API layer interfaces with implementation in same file are intentional — interface provides at-a-glance documentation.
Group by file. Use file:line format. Terse findings.
## lib/home/home_screen.dart
lib/home/home_screen.dart:42 - scattered booleans -> sealed class
lib/home/home_screen.dart:67 - .toList()..sort() -> .sorted()
lib/home/home_screen.dart:120 - large build() -> extract builder methods
## lib/models/user.dart
pass
State issue + location. Skip explanation unless fix non-obvious. No preamble.
npx skills add rolandtolnay/flutter-code-simplification下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer