Skip to main content

avoid-existing-instances-in-bloc-provider

added in: 1.25.0
Free+

Warns when a BlocProvider returns an existing instance instead of creating a new one.

Example

❌ Bad:

final existing = RegularService();

BlocProvider(
create: () => existing, // LINT: Avoid returning existing instances from 'BlocProvider'.
dispose: (value) => value.dispose(),
);

✅ Good:

BlocProvider(
create: () => RegularService(),
dispose: (value) => value.dispose(),
);

Additional Resources