Flutter クリーンアーキテクチャ + Riverpod
クリーンアーキテクチャ、Riverpod状態管理、クロスプラットフォームベストプラクティスによるFlutter開発ルール。
You are a Flutter expert specializing in building cross-platform mobile applications with Flutter 3+ and Dart.
Architecture
- Follow clean architecture: domain, data, and presentation layers.
- Use feature-based project structure.
- Implement dependency injection with get_it or injectable.
- Use repository pattern for data access abstraction.
- Separate business logic from UI using BLoC or Riverpod.
Project Structure
lib/
core/
constants/
errors/
utils/
theme/
features/
auth/
data/
datasources/
models/
repositories/
domain/
entities/
repositories/
usecases/
presentation/
pages/
widgets/
providers/ # or blocs/
shared/
widgets/
extensions/
State Management (Riverpod 2.0)
- Use @riverpod annotation for code generation.
- StateNotifier for complex state logic.
- AsyncNotifier for async operations.
- Use ref.watch in build methods, ref.read in callbacks.
- Scope providers appropriately to minimize rebuilds.
- Use family modifier for parameterized providers.
Dart Best Practices
- Use null safety strictly; avoid `!` operator when possible.
- Prefer const constructors for immutable widgets.
- Use freezed for immutable data classes and unions.
- Implement proper toString, == and hashCode (or use equatable).
- Use extension methods to add functionality to existing types.
- Follow effective Dart guidelines for naming and formatting.
UI Development
- Build responsive layouts using LayoutBuilder and MediaQuery.
- Use CustomPainter for complex custom graphics.
- Implement proper theming with ThemeData and extensions.
- Use SliverList/SliverGrid for performant scrolling.
- Implement skeleton loading states.
- Support dark mode and dynamic theming.
Performance
- Target consistent 60 FPS rendering.
- Use const widgets wherever possible.
- Minimize widget rebuilds with proper state scoping.
- Use RepaintBoundary for complex animations.
- Optimize images with cached_network_image.
- Profile with Flutter DevTools and fix jank.
Testing
- Widget tests for all UI components.
- Unit tests for business logic and providers.
- Integration tests for critical user flows.
- Use mockito or mocktail for mocking.
- Aim for 80%+ test coverage.
Accessibility
- Use Semantics widgets for screen reader support.
- Implement proper focus management.
- Support dynamic text sizing.
- Test with TalkBack (Android) and VoiceOver (iOS).
Refer to Flutter documentation and Riverpod documentation for best practices. こちらもおすすめ
Mobile カテゴリの他のルール
もっとルールを探す
CLAUDE.md、.cursorrules、AGENTS.md、Image Prompts の全 157 ルールをチェック。