prefer-immutable-bloc-events
Warns when a Bloc
event does not have the @immutable
annotation.
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-immutable-bloc-events:
name-pattern: Event$
Example
❌ Bad:
// LINT: Prefer adding '@immutable' to Bloc events.
sealed class CounterEvent {}
// LINT: Prefer adding '@immutable' to Bloc events.
class CounterIncrement extends CounterEvent {}
✅ Good:
sealed class CounterEvent {}
class CounterIncrement extends CounterEvent {}