Skip to content

Prefer File Naming Conventions

newdartrecommended

Prefer following file naming conventions.

For consistency, ease of maintenance, and separation of concerns prefer to define bloc and cubit instances in their respective Dart files instead of inlining them.

Prefer declaring bloc/cubit instances in their own respective files.

GOOD:

counter_cubit.dart
import 'package:bloc/bloc.dart';
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
}

BAD:

main.dart
import 'package:bloc/bloc.dart';
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
int increment() {
emit(state + 1);
return state;
}
}

To enable the prefer_file_naming_conventions rule, add it to your analysis_options.yaml under bloc > rules:

analysis_options.yaml
bloc:
rules:
- prefer_file_naming_conventions