0 purchases
computed value notifier
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 = '[email protected]';
print(emailValid.value); // prints 'true'.
copied to clipboard
Additional information #
Thanks to Brian Egan for the gist
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.