ReactterConsumer<T extends Object?> constructor

const ReactterConsumer<T extends Object?>({
  1. Key? key,
  2. String? id,
  3. ListenStates<T>? listenStates,
  4. bool listenAll = false,
  5. Widget? child,
  6. 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:

Implementation

const ReactterConsumer({
  Key? key,
  this.id,
  this.listenStates,
  this.listenAll = false,
  this.child,
  required this.builder,
}) : super(key: key);