Watcher class
A Widget that automatically tracks Property access and rebuilds when they change.
The Watcher is the primary way to consume state in Frost. It uses a smart tracking system that detects which properties are accessed within the watch builder and subscribes to them.
Basic Usage
final count = 0.property;
Watcher(
watch: (context) => Text("Count: ${count.value}"),
)
Lifecycle & Manual Signals
Watcher can replace StatefulWidget for simple lifecycle needs or explicit signal listening.
Watcher(
onInit: acquireSomeController,
onDispose: releaseController,
signal: myCustomSignal, // Rebuilds when this signal emits
signals: {signal1, signal2} // More than one signal can be connected if needed.
watch: (context) => const Text("Signal(s) emitted! Using some controller as well."),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- Watcher
Constructors
-
Watcher({Key? key, Property? property, Set<
Property> ? properties, Signal? signal, Set<Signal> ? signals, required Widget watch(BuildContext context), bool when()?, VoidCallback? onActivate, VoidCallback? onDeactivate, VoidCallback? onInit, VoidCallback? onDispose}) -
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- onActivate → VoidCallback?
-
A callback which is called when this widget is reinserted into the tree after having been
removed via deactivate method of the state object of this widget.
final
- onDeactivate → VoidCallback?
-
A callback which is called when the deactivate method of this widget's state is called.
final
- onDispose → VoidCallback?
-
A callback which does some work when the widget is disposed.
final
- onInit → VoidCallback?
-
A callback which does some work when the widget is created.
final
-
properties
→ Set<
Property> ? -
Optional Field for connecting to multiple properties.
final
- property → Property?
-
Optional property that when changed rebuilds the widget. Use when connecting only one property.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- signal → Signal?
-
Optional signal that when emitted rebuilds the widget. Use when connecting only one signal.
final
-
signals
→ Set<
Signal> ? -
Optional Field for connecting to multiple signals.
final
- watch → Widget Function(BuildContext context)
-
The builder for the widget that uses property inside itself.
final
- when → bool Function()?
-
Optional function that makes the watcher rebuild only when it returns true
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< Watcher> -
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