Selector5<A, B, C, D, E, S> class

An equivalent to Consumer that can filter updates by selecting a limited amount of values and prevent rebuild if they don't change.

Selector will obtain a value using Provider.of, then pass that value to selector. That selector callback is then tasked to return an object that contains only the information needed for builder to complete.

By default, Selector determines if builder needs to be called again by comparing the previous and new result of selector using DeepCollectionEquality from the package collection.

This behavior can be overridden by passing a custom shouldRebuild callback.

NOTE: The selected value must be immutable, or otherwise Selector may think nothing changed and not call builder again.

As such, it selector should return either a collection (List/Map/Set/Iterable) or a class that override ==.

Here's an example:

Example 1:

Selector<Foo, Bar>(
  selector: (_, foo) => foo.bar,  // will rebuild only when `bar` changes
  builder: (_, data, __) {
    return Text('${data.item}');
  }
)

In this example builder will be called only when foo.bar changes.

Example 2:

To select multiple values without having to write a class that implements ==, the easiest solution is to use "Records," available from Dart version 3.0. For more information on Records, refer to the records.

Selector<Foo, ({String item1, String item2})>(
  selector: (_, foo) => (item1: foo.item1, item2: foo.item2),
  builder: (_, data, __) {
    return Text('${data.item1}  ${data.item2}');
  },
);

In this example, builder will be called again only if foo.item1 or foo.item2 changes.

For generic usage information, see Consumer.

Inheritance

Constructors

Selector5({Key? key, required ValueWidgetBuilder<S> builder, required S selector(BuildContext, A, B, C, D, E), ShouldRebuild<S>? shouldRebuild, Widget? child})
An equivalent to Consumer that can filter updates by selecting a limited amount of values and prevent rebuild if they don't change.

Properties

builder ValueWidgetBuilder<S>
A function that builds a widget tree from child and the last result of selector.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selector → S Function(BuildContext)
A function that obtains some InheritedWidget and map their content into a new object with only a limited number of properties.
finalinherited

Methods

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