Observer<T> class
A widget that rebuilds whenever the given observable emits a new value.
Similar to ValueListenableBuilder, but built around custom IObservable. Useful for simple UI bindings with minimal boilerplate.
Example usage: Observer(counter, (count) => Text('Count: $count')); or: Observer.builder( observable: counter, builder: (context, value) => Text('Count: $value'), );
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- Observer
Constructors
-
Observer(IObservable<
T> observable, Widget builder(T v), {Key? key}) -
Shorthand constructor for when you don't need BuildContext in your builder.
factory
-
Observer.builder({Key? key, required IObservable<
T> observable, required Widget builder(BuildContext ctx, T val)}) -
Builder constructor with access to both BuildContext and value.
factory
Properties
- builder → Widget Function(BuildContext, T)
-
The builder function that builds the UI based on the observable value.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
observable
→ IObservable<
T> -
The observable to listen to.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< Observer< 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, int wrapWidth = 65}) → 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
Static Methods
-
multi(
{Key? key, required List< IObservable> observables, required Widget builder(BuildContext)}) → MultiObserver - Creates a MultiObserver that listens to a list of observables, and rebuilds the widget whenever any of them changes.
-
select<
T, R> ({Key? key, required IObservable< T> observable, required R selector(T), required Widget builder(BuildContext, R)}) → ObserverSelect<T, R> -
Creates an ObserverSelect that listens to changes from an observable,
and only rebuilds the widget when the selected value (from
selector) changes. -
three<
A, B, C> ({Key? key, required IObservable< A> o1, required IObservable<B> o2, required IObservable<C> o3, required Widget builder(BuildContext, A, B, C)}) → Observer3<A, B, C> -
Creates an Observer3 that listens to three observables
o1,o2, ando3, and rebuilds the widget whenever any of the values change. -
two<
A, B> ({Key? key, required IObservable< A> o1, required IObservable<B> o2, required Widget builder(BuildContext, A, B)}) → Observer2<A, B> -
Creates an Observer2 that listens to two observables
o1ando2, and rebuilds the widget whenever either value changes.