Skip to content

use_bloc_suffix

v0.1.0 Warning Fix Class Naming

This rule flags classes that extend Bloc but don’t include the Bloc suffix in their name. Consistent naming makes it immediately clear which classes are Blocs when scanning through code or reading imports.

When a class extends Bloc but is named something like CounterManager or AuthHandler, other developers have to check the inheritance chain to understand what it is. The Bloc suffix is a widely adopted convention in the Flutter/Bloc ecosystem that makes the architectural role of each class obvious at a glance.

See also: Bloc naming conventions

import 'package:bloc/bloc.dart';
abstract class CounterEvent {}
class Increment extends CounterEvent {}
// Missing 'Bloc' suffix
class CounterManager extends Bloc<CounterEvent, int> {
CounterManager() : super(0) {
on<Increment>((event, emit) => emit(state + 1));
}
}
import 'package:bloc/bloc.dart';
abstract class CounterEvent {}
class Increment extends CounterEvent {}
class CounterBloc extends Bloc<CounterEvent, int> {
CounterBloc() : super(0) {
on<Increment>((event, emit) => emit(state + 1));
}
}

To disable this rule:

plugins:
many_lints:
diagnostics:
use_bloc_suffix: false