Skip to main content

prefer-correct-bloc-provider

added in: 1.2.0
🛠
Pro+

Warns when a Bloc is provided not with a BlocProvider.

If you use both bloc and provider packages it becomes easy to accidentally use the wrong Provider for your Blocs.

Example

❌ Bad:

// LINT: Prefer providing 'Blocs' via 'BlocProvider'.
final provider = Provider<BlocA>(
create: (context) => BlocA(),
child: Widget(),
);

✅ Good:

final blocProvider = BlocProvider<BlocA>(
create: (context) => BlocA(),
child: Widget(),
);