prefer-bloc-extensions
Suggests using context.read()
or context.watch()
instead of BlocProvider.of(context)
.
Using context
extensions is shorter, helps you keep the codebase consistent and makes it less likely to forget listen: true
when watch
behavior is expected.
Example
❌ Bad:
// LINT: Prefer 'context.read' instead of 'BlocProvider.of'.
BlocProvider.of(context);
// LINT: Prefer 'context.read' instead of 'BlocProvider.of'.
BlocProvider.of<String>(context);
// LINT: Prefer 'context.watch' instead of 'BlocProvider.of(listen: true)'.
BlocProvider.of<String>(context, listen: true);
✅ Good:
context.watch();
context.read();