Skip to content

HosamHasanRamadan/computed_value_notifier

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages