prefer-multi-bloc-provider
Warns when a BlocProvider
/ BlocListener
/ RepositoryProvider
can be replace with a Multi
version.
Replacing with multi provider improves the readability and reduces the widget tree nesting level.
Example
❌ Bad:
// LINT: Prefer 'MultiBlocProvider' instead of multiple nested 'BlocProviders'.
final provider = BlocProvider<BlocA>(
create: (context) => BlocA(),
child: BlocProvider<BlocB>(
create: (context) => BlocB(),
child: BlocProvider<BlocC>(
create: (context) => BlocC(),
child: Widget(),
),
),
);
✅ Good:
final multiProvider = MultiBlocProvider(
providers: [
BlocProvider<BlocA>(create: (context) => BlocA()),
BlocProvider<BlocB>(create: (context) => BlocB()),
BlocProvider<BlocC>(create: (context) => BlocC()),
],
child: Widget(),
);