SubValue<T> class
Creates, recreates, updates and disposes a Value T.
SubValue calls create to create a value. The created value is provided to its child widgets through the builder.
Changing the return value of keys will trigger another call to create. The updated value is then passed to builder and the widget is rebuilt. If no value is passed for keys, the value is created once only and persist for the lifetime of this widget.
The value can be updated by specifying the update parameter. This is useful if the created value is a controller, and its values rely on other variables up in the tree.
To release any allocated resources, the value can be disposed with the dispose callback. dispose is called for every value that is discarded when keys change and once this widget is disposed entirely.
The following example SubValue shows an example of creating a Stream for a search from our database. The stream is recreated when either the database or the search changes. The Stream can then be used in a StreamBuilder. The stream is appropriately kept in a State while we do not need an extra StatefulWidget.
return SubValue(
create: () => database.findItems(search),
keys: [database, search],
builder: (context, stream) => StreamBuilder(
stream: stream,
builder: (context, snapshot) => /* ... */,
),
);
Constructors
-
SubValue({required SubValueCreate<
T> create, SubValueKeys? keys, SubValueUpdate<T> ? update, SubValueDispose<T> ? dispose, required SubValueBuild<T> builder}) - Creates, recreates, updates and disposes a Value T.
-
SubValue.builder({required SubValueBuilderCreate<
T> create, SubValueBuilderKeys? keys, SubValueBuilderUpdate<T> ? update, SubValueBuilderDispose<T> ? dispose, required SubValueBuild<T> builder}) -
Creates, recreates, updates and disposes a Value T.
const
Properties
-
builder
→ SubValueBuild<
T> -
Creates the child of this Widget with the value.
final
-
create
→ SubValueBuilderCreate<
T> -
Creates the value. Called at least once and everytime keys changes.
final
-
dispose
→ SubValueBuilderDispose<
T> ? -
Disposes the value. Called before recreation and when disposing. Useful for Listeners, etc.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- keys → SubValueBuilderKeys?
-
Used to decide when to recreate the value. If null, the value is never recreated.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
update
→ SubValueBuilderUpdate<
T> ? -
Updates the value. Called every build. If null, does nothing.
In the call order, this comes after recreating the value.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< SubValue< 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