SubscriberGadget<T> class

A Gadget used to observe a specified value from the ObservableModel.

Using the type T and the optional token, a SubscriberGadget registers itself as a listener for the subject associated to T and token in the ObservableModel and rebuilds itself each time a new value is added to the subject - either by using ObservableModel.putValue, ObservableModel.updateValue or ObservableModel.notifyFor.

When propertiesSelector is specified, builder will be called only if the current values of the selected properties and the previous ones - compared using DeepCollectionEquality from the package collection - are different.

If the useEquality flag is true, whenever a rebuild is requested, the builder function will be called only if the current value of the observed object and the previous one - compared using the == operator - are different.

If the current value of the observed object is null, SubscriberGadget will use the nullBuilder function instead of the builder. An exception will be thrown if the previous condition is true, but the nullBuilder value is null.

It is used as follows:

SubscriberGadget<MyValue>(
  builder: (context, value) => Text('My value $value'),
  nullBuilder: (context) => Text('My value is null...'),
)
SubscriberGadget<MyValue>(
  propertiesSelector: (value) => [value.firstProperty]
  builder: (context, value) => Text('First property $value.firstProperty'),
  nullBuilder: (context) => Text('My value is null...'),
)
SubscriberGadget<int>(
  useEquality: true,
  builder: (context, value) => Text('int value $value'),
  nullBuilder: (context) => Text('int value is null...'),
)
Inheritance

Constructors

SubscriberGadget({Key? key, required SubscriberGadgetBuilder<T> builder, NullGadgetBuilder? nullBuilder, PropertiesSelector<T>? propertiesSelector, String? token, bool useEquality = false})
const

Properties

builder → SubscriberGadgetBuilder<T>
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
nullBuilder → NullGadgetBuilder?
final
propertiesSelector → PropertiesSelector<T>?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
token String?
final
useEquality bool
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _SubscriberGadgetState<T>
Creates the mutable state for this widget at a given location in the tree.
override
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