Flutter Development Standards

seedlingLast update on Jul 9, 2026
Download .md

Architecture

Gunakan Clean Architecture dengan BLoC (Business Logic Component) untuk state management.

lib/
├── core/                 # Shared utilities, theme, constants
├── features/
│   └── auth/
│       ├── data/         # Repositories, models, datasources
│       ├── domain/       # Entities, use cases
│       └── presentation/ # BLoC, screens, widgets
├── main.dart
└── injection.dart        # GetIt DI setup

State Management

Gunakan flutter_bloc (Cubit untuk simple, Bloc untuk complex):

class AuthCubit extends Cubit<AuthState> {
    AuthCubit(this._repo) : super(AuthInitial());

    final AuthRepository _repo;

    Future<void> login(String email, String password) async {
        emit(AuthLoading());
        try {
            final user = await _repo.login(email, password);
            emit(AuthSuccess(user));
        } catch (e) {
            emit(AuthError(e.toString()));
        }
    }
}

Gunakan GoRouter untuk declarative routing:

final router = GoRouter(
    routes: [
        GoRoute(path: '/', builder: (_, __) => HomeScreen()),
        GoRoute(path: '/login', builder: (_, __) => LoginScreen()),
    ],
);

Dependency Injection

Gunakan GetIt untuk DI:

final getIt = GetIt.instance;

void setupDependencies() {
    getIt.registerSingleton<AuthRepository>(AuthRepositoryImpl());
    getIt.registerFactory(() => AuthCubit(getIt()));
}

Testing

# Unit test
flutter test

# Integration test
flutter test integration_test/

Code Quality

# Format
dart format .

# Analyze
dart analyze

# Linter (di pubspec.yaml)
analyzer:
    enable-experiment:
        - records
        - patterns