flutter-dart-code-review
できること
Flutter と Dart のコードをレビューするためのガイドです。状態管理に使うライブラリにかかわらず、コードが整理されているか、良いプログラミングの習慣に沿っているか、よくあるエラーを避けているかを確認します。
使う場面
- ✓他の人が書いたコードをレビューするとき。
- ✓機能を完成させる前。
- ✓Flutter/Dart のベストプラクティスを学びたいとき。
スキルのリンク
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/flutter-dart-code-review/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このFlutterコードをレビューして、整理の仕方のベストプラクティスと、起こりうるエラーに注目して確認してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このガイドでは、プロジェクトの構成、Dart言語の正しい使い方、ウィジェット(画面の見た目の部品)を作る際のベストプラクティス、状態(変化するデータ)の管理方法を確認します。コードが効率的で、アクセシブルで、安全であることを確かめます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Flutter/Dart Code Review Best Practices
Comprehensive, library-agnostic checklist for reviewing Flutter/Dart applications. These principles apply regardless of which state management solution, routing library, or DI framework is used.
1. General Project Health
- Project follows consistent folder structure (feature-first or layer-first)
- Proper separation of concerns: UI, business logic, data layers
- No business logic in widgets; widgets are purely presentational
-
pubspec.yamlis clean — no unused dependencies, versions pinned appropriately -
analysis_options.yamlincludes a strict lint set with strict analyzer settings enabled - No
print()statements in production code — usedart:developerlog()or a logging package - Generated files (
.g.dart,.freezed.dart,.gr.dart) are up-to-date or in.gitignore - Platform-specific code isolated behind abstractions
2. Dart Language Pitfalls
- Implicit dynamic: Missing type annotations leading to
dynamic— enablestrict-casts,strict-inference,strict-raw-types - Null safety misuse: Excessive
!(bang operator) instead of proper null checks or Dart 3 pattern matching (if (value case var v?)) - Type promotion failures: Using
this.fieldwhere local variable promotion would work - Catching too broadly:
catch (e)withoutonclause; always specify exception types - Catching
Error:Errorsubtypes indicate bugs and should not be caught - Unused
async: Functions markedasyncthat neverawait— unnecessary overhead -
lateoveruse:lateused where nullable or constructor initialization would be safer; defers errors to runtime - String concatenation in loops: Use
StringBufferinstead of+for iterative string building - Mutable state in
constcontexts: Fields inconstconstructor classes should not be mutable - Ignoring
Futurereturn values: Useawaitor explicitly callunawaited()to signal intent -
varwherefinalworks: Preferfinalfor locals andconstfor compile-time constants - Relative imports: Use
package:imports for consistency - Mutable collections exposed: Public APIs should return unmodifiable views, not raw
List/Map - Missing Dart 3 pattern matching: Prefer switch expressions and
if-caseover verboseischecks and manual casting - Throwaway classes for multiple returns: Use Dart 3 records
(String, int)instead of single-use DTOs -
print()in production code: Usedart:developerlog()or the project's logging package;print()has no log levels and cannot be filtered
3. Widget Best Practices
Widget decomposition:
- No single widget with a
build()method exceeding ~80-100 lines - Widgets split by encapsulation AND by how they change (rebuild boundaries)
- Private
_build*()helper methods that return widgets are extracted to separate widget classes (enables element reuse, const propagation, and framework optimizations) - Stateless widgets preferred over Stateful where no mutable local state is needed
- Extracted widgets are in separate files when reusable
Const usage:
-
constconstructors used wherever possible — prevents unnecessary rebuilds -
constliterals for collections that don't change (const [],const {}) - Constructor is declared
constwhen all fields are final
Key usage:
-
ValueKeyused in lists/grids to preserve state across reorders -
GlobalKeyused sparingly — only when accessing state across the tree is truly needed -
UniqueKeyavoided inbuild()— it forces rebuild every frame -
ObjectKeyused when identity is based on a data object rather than a single value
Theming & design system:
- Colors come from
Theme.of(context).colorScheme— no hardcodedColors.redor hex values - Text styles come from
Theme.of(context).textTheme— no inlineTextStylewith raw font sizes - Dark mode compatibility verified — no assumptions about light background
- Spacing and sizing use consistent design tokens or constants, not magic numbers
Build method complexity:
- No network calls, file I/O, or heavy computation in
build() - No
Future.then()orasyncwork inbuild() - No subscription creation (
.listen()) inbuild()
…
よくある質問
「ライブラリに依存しない」とはどういう意味ですか?
Flutterプロジェクトで使っている状態管理ライブラリ(BLoC、Riverpod、Providerなど)が何であっても、このガイドのヒントが使えるという意味です。
最終的なコードで `print()` を使わないのはなぜですか?
`print()` はアプリのログを散らかしやすく、重要度のレベルを持たないため、重要なメッセージを見つけにくくなります。専用のログツールを使う方がよいです。
「ウィジェット」とは何ですか?
ウィジェットは Flutter でユーザーインターフェースを組み立てる部品です。テキスト、ボタン、レイアウトなど、画面上の見た目の要素を表します。
詳細
作者による元の説明
Library-agnostic Flutter/Dart code review checklist covering widget best practices, state management patterns (BLoC, Riverpod, Provider, GetX, MobX, Signals), Dart idioms, performance, accessibility, security, and clean architecture. Use when reviewing Flutter or Dart code, whatever state management library the project uses.
repo: affaan-m/ECC
人気
- GitHubのスター
- 280k
- ランキング
- #180
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
accessibility
280kエージェントが誰にとっても使いやすいインターフェースを作れるように手助けします。目が見えない方や身体の動きに制限のある方など、障害のある人にとってもWebサイトやアプリが正しく動くようにします。
agent-architecture-audit
280kエージェントがすべて正しく動いているかを確認できるようにします。AIシステムの問題を見つけて修正し、期待どおりに動くようにします。
agent-eval
280kエージェントが異なるAIコーディングツールを比較できるようにします。特定のタスクにおいて、どれがより速く、安く、信頼性が高いかを測定します。
agent-harness-construction
280kエージェントがタスクの進め方をよりよく理解できるようにします。エージェントが使うツールや指示を最適化し、成功する可能性を高めます。
似ているスキル
flutter-animating-apps
101kFlutterアプリにアニメーション効果やトランジションを追加できるようにします。iOSやAndroidアプリで動きやビジュアルデザインを作るのに役立ちます。
agent-spec-mobile-react-native
81kReact Nativeで、iPhoneとAndroidのモバイルアプリを、画面、ナビゲーション、ネイティブモジュールを含めて作る手助けをします。
orientation
75kエージェントが縦向きと横向きの両方でサイトが機能するようにし、画面の向きの固定や「端末を回転させてください」という表示を取り除いて、人々がコンテンツを見られるようにします。