home / skills / hoangnguyen0403 / agent-skills-standard / idiomatic-flutter
This skill helps you write idiomatic Flutter layouts by enforcing modern patterns, composition, and performance-friendly widget usage.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill idiomatic-flutterReview the files below or copy the command above to add this skill to your agents.
---
name: Idiomatic Flutter
description: Modern layout and widget composition standards.
metadata:
labels: [flutter, clean-code, widgets]
triggers:
files: ['lib/presentation/**/*.dart']
keywords: [context.mounted, SizedBox, Gap, composition, shrink]
---
# Idiomatic Flutter
## **Priority: P1 (OPERATIONAL)**
Modern Flutter layout patterns and composition techniques.
- **Async Gaps**: Check `if (context.mounted)` before using `BuildContext` after `await`.
- **Composition**: Extract complex UI into small widgets. Avoid deep nesting or large helper methods.
- **Layout**:
- Spacing: Use `Gap(n)` or `SizedBox` over `Padding` for simple gaps.
- Empty UI: Use `const SizedBox.shrink()`.
- Intrinsic: Avoid `IntrinsicWidth/Height`; use `Stack` + `FractionallySizedBox` for overlays.
- **Optimization**: Use `ColoredBox`/`Padding`/`DecoratedBox` instead of `Container` when possible.
- **Themes**: Use extensions for `Theme.of(context)` access.
## 🚫 Anti-Patterns
- **Missing Mounted Check**: `**No context usage after await**: Always check if (context.mounted).`
- **Helper Methods for UI**: `**No Widget functions**: Use specialized Widget classes for better performance/profiling.`
- **Direct Controller Access**: `**No UI-Logic coupling**: Use BLoC/Signals to decouple UI from State.`
This skill encapsulates modern Flutter layout and widget composition standards for building robust, maintainable UIs. It highlights defensive async patterns, composition over nesting, layout choices, and lightweight optimizations to improve performance and readability. Use it as a checklist for code reviews, linters, and agent-guided refactors.
The skill inspects Flutter/Dart UI code for common operational patterns and anti-patterns. It flags missing mounted checks after await points, excessive widget helper functions, improper controller coupling, and suboptimal layout or container usage. It also recommends idiomatic replacements like Gap, SizedBox.shrink, ColoredBox, and theme extensions.
Why check context.mounted after await?
BuildContext may become invalid if the widget was disposed while awaiting; checking context.mounted prevents exceptions and stale UI updates.
When should I extract a helper method into a Widget class?
Extract when a UI subtree is reused, complex, or causes deep nesting. Widget classes enable better profiling, faster rebuilds, and clearer responsibilities.
Is Container always a bad choice?
No. Container is convenient but heavier. Use lighter primitives like ColoredBox, Padding, or DecoratedBox when you only need a subset of Container features to reduce layout overhead.