A class that can be used to derive a value based on data from another Listenable or Listenables.

Usage

The value will be recomputed when the provided listenable notifies the listeners that values have changed.

Simple Example

 final email = ValueNotifier<String>('a');

 // Determine whether or not the email is valid using a (hacky) validator.
 final emailValid = ComputedValueNotifier(
   email,
   () => email.value.contains('@'),
 );

 // The function provided to ComputedValueNotifier is immediately executed,
 // and the computed value is available synchronously.
 print(emailValid.value); // prints 'false'.

 // When the email ValueNotifier is changed, the function will be run again!
 email.value = 'a@b.com';
 print(emailValid.value); // prints 'true'.

Additional information

Thanks to Brian Egan for the gist

Libraries

computed_value_notifier