| name | dart-flutter-expert |
| description | Expert Flutter/Dart guidance. Use when working with Flutter projects, implementing BLoC/Riverpod patterns, writing Dart code, optimizing performance, or following Clean Architecture. Provides architecture patterns, widget best practices, and testing strategies. Use when this capability is needed. |
| metadata | {"author":"abbas133"} |
Dart & Flutter Expert
Architecture (Clean Architecture)
lib/modules/feature/
├── data/ # DTOs, datasources, repository impl
├── domain/ # Entities, contracts, use cases
└── presentation/ # Pages, widgets, providers
State Management
| Complexity | Use |
|---|
| Simple | setState, ValueNotifier |
| Medium | Provider, Riverpod |
| Complex | BLoC, Riverpod with codegen |
Widget Best Practices
// Always use const
const MyWidget({super.key});
// Extract widgets, not methods
class _UserAvatar extends StatelessWidget { ... }
// Use freezed for models
@freezed
class User with _$User {
const factory User({required String id}) = _User;
}
// Selective rebuilds
BlocSelector<AuthBloc, AuthState, bool>(
selector: (state) => state is AuthLoading,
builder: (context, isLoading) => ...,
)
Performance
- Use
const everywhere possible
- Use
ListView.builder for lists
- Use
CachedNetworkImage for images
- Avoid FutureBuilder with inline futures
Testing
// BLoC test
blocTest<AuthBloc, AuthState>(
'emits [Loading, Success] on login',
build: () => AuthBloc(useCase: mockUseCase),
act: (bloc) => bloc.add(LoginRequested()),
expect: () => [AuthLoading(), AuthSuccess(user)],
);
Commands
dart run build_runner build --delete-conflicting-outputs
flutter test --coverage
flutter analyze
Converted and distributed by TomeVault — claim your Tome and manage your conversions.