ReactterConsumer<T extends Object?> constructor
const
ReactterConsumer<T extends Object?> ({
- Key? key,
- String? id,
- ListenStates<
T> ? listenStates, - bool listenAll = false,
- Widget? child,
- required InstanceChildBuilder<
T> builder,
A StatelessWidget that allows to obtain an instance of T
type
from the closest ancestor ReactterProvider and passes the instance
to builder.
Also, listens for instance changes or a ReactterState list to rebuild the widget tree.
ReactterConsumer has same functionality as ReactterProvider.contextOf.
Use id property to identify the T
instance.
Use listenAll property to listen changes to the instance or the states defined in listenStates property:
ReactterConsumer<AppController>(
listenStates: (inst) => [inst.stateA],
builder: (context, appController, child) {
return Column(
children: [
Text("state: ${appController.stateA.value}"),
child,
],
);
},
)
Use child property to pass a Widget which to be built once only. It will be sent through the builder callback, so you can incorporate it into your build:
ReactterConsumer<AppController>(
listenAll: true,
child: Text("This widget build only once"),
builder: (context, appController, child) {
return Column(
children: [
Text("state: ${appController.stateA.value}"),
child,
],
);
},
)
See also:
- ReactterState, a state in reactter.
- ReactterProvider, a widget that provides a
T
instance through Widget. tree.
Implementation
const ReactterConsumer({
Key? key,
this.id,
this.listenStates,
this.listenAll = false,
this.child,
required this.builder,
}) : super(key: key);