MultiRepositoryProvider constructor
MultiRepositoryProvider({})
Merges multiple RepositoryProvider widgets into one widget tree.
MultiRepositoryProvider improves the readability and eliminates the need to nest multiple RepositoryProviders.
By using MultiRepositoryProvider we can go from:
RepositoryProvider<RepositoryA>(
create: (context) => RepositoryA(),
child: RepositoryProvider<RepositoryB>(
create: (context) => RepositoryB(),
child: RepositoryProvider<RepositoryC>(
create: (context) => RepositoryC(),
child: ChildA(),
)
)
)
to:
MultiRepositoryProvider(
providers: [
RepositoryProvider<RepositoryA>(create: (context) => RepositoryA()),
RepositoryProvider<RepositoryB>(create: (context) => RepositoryB()),
RepositoryProvider<RepositoryC>(create: (context) => RepositoryC()),
],
child: ChildA(),
)
MultiRepositoryProvider converts the RepositoryProvider list into a tree of nested RepositoryProvider widgets. As a result, the only advantage of using MultiRepositoryProvider is improved readability due to the reduction in nesting and boilerplate.
Implementation
MultiRepositoryProvider({
required List<SingleChildWidget> providers,
required Widget child,
Key? key,
}) : super(key: key, providers: providers, child: child);