ReactterProviders constructor
const
ReactterProviders(
- List<
ProviderWrapper> providers, { - Key? key,
- Widget? child,
- ChildBuilder? builder,
A StatelessWidget that allows to use multiple ReactterProvider as nested way.
ReactterProviders(
[
ReactterProvider(() => AppController()),
ReactterProvider(() => AppController(), id: "uniqueId"),
],
builder: (context, child) {
final appController = context.read<AppController>();
final appControllerWithId = context.watchId<AppController>("uniqueId");
return Column(
children: [
Text("AppController's state: ${appController.stateHook.value}"),
Text("appControllerWithId's state: ${appController.stateHook.value}");
],
);
}
)
Use child property to pass a Widget which to be built once only. The ReactterProviders pass it through the builder callback, so you can incorporate it into your build:
ReactterProviders(
[
ReactterProvider(() => AppController()),
ReactterProvider(() => AppController(), id: "uniqueId"),
],
child: Text("This widget build only once"),
builder: (context, child) {
final appController = context.read<AppController>();
final appControllerWithId = context.watchId<AppController>("uniqueId");
return Column(
children: [
child,
Text("AppController's state: ${appController.stateHook.value}"),
Text("appControllerWithId's state: ${appController.stateHook.value}");
],
);
}
)
See also:
- ReactterProvider, a widget that provides an instance type to widget tree.
Implementation
const ReactterProviders(
this.providers, {
Key? key,
this.child,
this.builder,
}) : assert(child != null || builder != null),
super(key: key);