ReactterConsumer<T extends Object?> class

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:

Inheritance

Constructors

ReactterConsumer({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.
const

Properties

builder InstanceChildBuilder<T>
Method which is responsible for building the widget tree.
final
child Widget?
Use to pass a single child widget that will be built once and incorporated into the widget tree.
final
hashCode int
The hash code for this object.
no setterinherited
id String?
This identifier can be used to differentiate between multiple instances of the same type T in the widget tree when using ReactterProvider.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
listenAll bool
Watchs all states to re-build builder method.
final
listenStates ListenStates<T>?
Listens states to re-build builder method.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited