Skip to main content

prefer-sealed-bloc-events

added in: 1.24.0
⚙️
Free+

Warns when Bloc events do not have a sealed or final modifier.

info

If you keep your bloc events in separate files, consider using the include configuration option to scope the rule to only those files.

⚙️ Config

Set name-pattern (default is Event$) to set a regular expression pattern for bloc event names.

analysis_options.yaml
dart_code_metrics:
rules:
- prefer-sealed-bloc-events:
name-pattern: Event$

Example

❌ Bad:

// LINT: Prefer adding a 'sealed' or 'final' modifier to Bloc events.
abstract class CounterEvent {}

// LINT: Prefer adding a 'sealed' or 'final' modifier to Bloc events.
class CounterIncrement extends CounterEvent {}

// LINT: Prefer adding a 'sealed' or 'final' modifier to Bloc events.
class CounterDecrementEvent extends CounterEvent {}

✅ Good:

sealed class CounterEvent {}

final class CounterIncrementEvent extends CounterEvent {}

final class CounterDecrementEvent extends CounterEvent {}