ReactiveBlockRef class abstract

Read access to observables that also subscribes the caller to them.

An Obx builder receives a ref; every observable read through watch during that build is tracked, and a change to any of them rebuilds the block. Values read without watch are not tracked.

Take ReactiveBlockRef as a parameter to move derived state out of the builder while keeping the subscriptions — a widely used idiom for computed properties on a state class:

class EditExerciseState {
  final title = Rx<String>('');
  final videoUrl = Rx<String?>(null);

  bool isValid(ReactiveBlockRef ref) =>
      ref.watch(title).isNotEmpty && ref.watch(videoUrl) != null;
}

Obx((ref) => SaveButton(enabled: state.isValid(ref)))
Implementers

Constructors

ReactiveBlockRef()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
watch<T>(ValueListenable<T> observable) → T
Returns the current value of observable and subscribes the enclosing reactive block to it.

Operators

operator ==(Object other) bool
The equality operator.
inherited