prefer-sealed-bloc-state
Warns when Bloc
state classes do not have a sealed
or final
modifier.
info
If you keep your bloc state in separate files, consider using the include
configuration option to scope the rule to only those files.
⚙️ Config
Set name-pattern
(default is State$
) to set a regular expression pattern for bloc state.
analysis_options.yaml
dart_code_metrics:
rules:
- prefer-sealed-bloc-state:
name-pattern: State$
Example
❌ Bad:
// LINT: Prefer adding a 'sealed' or 'final' modifier to Bloc state.
abstract class CounterState {}
// LINT: Prefer adding a 'sealed' or 'final' modifier to Bloc state.
class CounterIncrementState extends CounterState {}
// LINT: Prefer adding a 'sealed' or 'final' modifier to Bloc state.
class CounterDecrementState extends CounterState {}
✅ Good:
sealed class CounterState {}
final class CounterIncrementState extends CounterState {}
final class CounterDecrementState extends CounterState {}