WatchValue<T> class

WatchValue Widget

A widget that simplifies the integration and usage of Watcher instances within the Flutter UI. It efficiently handles the rendering of widgets in response to state changes.

The WatchValue widget takes a Watcher instance and a builder function. The builder function is responsible for returning the widget that should be rendered based on the current value of the Watcher. This setup ensures that the widget is automatically updated whenever the Watcher's value changes, making it highly efficient for creating reactive UI components.

The widget can be used directly with any Watcher instance, including those created via the watch extension on various types, such as bool, int, List, and more.

Usage:

final isLoading = false.watcher;

@override
Widget build(BuildContext context) {
  return WatchValue<bool>(
    builder: (context, value) => MyWidget(value), // Builder function
    watcher: isLoading, // Watcher instance
  );
}

Alternatively, the watchValue extension method can be used for a more concise syntax:

@override
Widget build(BuildContext context) {
  return isLoading.watchValue(
    (value) => MyWidget(value),
  );
}

WatchValue is an essential part of the flutter_watcher package, streamlining state management in Flutter applications and facilitating the development of responsive and dynamic user interfaces.

Inheritance

Constructors

WatchValue({required ValueListenable<T> watcher, required Widget builder(BuildContext context, T value), bool watchWhen(T previous, T current)?, Duration? threshold, Key? key})
const

Properties

builder Widget Function(BuildContext context, T value)
builder
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?
threshold
final
watcher ValueListenable<T>
watcher
final
watchWhen → (bool Function(T previous, T current)?)
watchWhen
final

Methods

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