Watch class

Watch

A flexible widget that rebuilds itself in response to changes in any Listenable object, including Watcher instances. It monitors a specified watcher and triggers a rebuild whenever the watcher notifies its listeners of updates.

The Watch widget is compatible with both custom and Flutter's native Listenable objects. This includes, but is not limited to, ValueNotifier, AnimationController, ScrollController and TextEditingController. Its adaptability makes it ideal for various state management approaches, integrating seamlessly with both custom Listenable implementations and Flutter’s own state management systems.

Inheritance

Constructors

Watch({required Listenable watcher, required Widget builder(BuildContext context), bool watchWhen()?, Duration? threshold, Key? key})
const

Properties

builder Widget Function(BuildContext context)
A function that defines the widget to be built based on the current context. This function is called whenever the widget needs to rebuild, providing the flexibility to design responsive and dynamic UI components that react to state changes.
final
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
threshold Duration?
An optional Duration that sets a time limit for how frequently the widget can rebuild in response to watchers notifications. If set, the widget will only consider rebuilding after this duration has elapsed since the last rebuild, providing a way to limit the frequency of rebuilds during rapid state changes. This feature is particularly useful for optimizing performance and avoiding flickering in the UI.
final
watcher Listenable
A Listenable object that this widget is listening to. A Listenable
final
watchWhen → (bool Function()?)
An optional callback that determines whether the widget should rebuild when any of the watchers notify their listeners. It can be used to optimize performance by preventing unnecessary rebuilds. If it returns true, the builder function is called to rebuild the widget. If false, the widget is not rebuilt. If left null, the widget rebuilds on every notification from the watchers.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<Watch>
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