Valuable<Output> class
abstract
Main class Valuable
This class inherits of ChangeNotifier to manage its events.
It's importance to notice that the dispose of this object has to be done to avoid memory leaks and useless remaining references. For these reasons, the method dispose should be called when the object isn't used anymore.
It's possible to know if the Valuable object is still mounted by testing getter isMounted. When isMounted becomes false, it can't back to true, this object will die. Furthermore, it's possible to listen for the object unmounting by using the method listenDispose.
This class defines 2 factories to build simpler Valuable:
- Valuable.value represent a Valuable at its simplest form : a value. No function, no dependencies, just a value that would be returned by getValue
- Valuable.computed which is more complex but even more powerful. Indeed, the
valuer
param is a function, where Valuable calculate its self value. In fact it's even possible to depends on other Valuables, whose values are possibly changeable. When these Valuable values change, our Valuable is notified, and notify at its turn to be read again.
Lastly, the most useful method, getValue. Simple as its name, this method returns the current value of the Valuable (final or calculated). In addition, it's even possible to pass a ValuableContext to specify the context where the value is needed.
- Inheritance
-
- Object
- ChangeNotifier
- Valuable
- Implementers
- Available Extensions
Constructors
- Valuable({bool evaluateWithContext = false})
-
Valuable.byValuer(ValuableParentWatcher<
Output> valuer, {bool evaluateWithContext = false}) -
Replace by Valuable.computed.
factory
-
Valuable.computed(ValuableParentWatcher<
Output> computation, {bool evaluateWithContext = false}) -
Factory Valuable.computed to build a Valuable that calculate its own value
through a function.
factory
-
Valuable.listenable(ValueListenable<
Output> listenable) -
Factory Valuable.listenable to build a Valuable that listen
to a ValueListenable and provide its value
factory
- Valuable.value(Output value)
-
Factory Valuable.value to build a simple Valuable on a final value
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isMounted → bool
-
Returns if this object is still mounted
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- valuableContext → ValuableContext?
-
no setterinherited
- valueCache → _ValueCache
-
final
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
cleanWatched(
) → void -
inherited
-
dispose(
) → void -
Should be called to clean all links to other Valuables, and all the rest
override
-
equals(
dynamic other) → Valuable< bool> -
Compare with a value that type is
Output
or another Valuable -
getValue(
[ValuableContext? context = const ValuableContext()]) → Output - Get the current value of the Valuable
-
getValueDefinition(
bool reevaluatingNeeded, [ValuableContext? context = const ValuableContext()]) → Output - This method should be redefined in ever sub-classes to determine how works the method getValue
-
historize(
) → HistorizedValuable< Output> - Build an HistorizedValuable based on this Valuable
-
listenDispose(
VoidCallback onDispose) → void - Allows to be notified when this Valuable is disposed
-
map<
Other> (Other toElement(Output)) → Valuable< Other> -
A method to map a Valuable from
Output
toOther
-
markToReevaluate(
) → void - Mark the valuable to be reevaluated
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notEquals(
dynamic other) → Valuable< bool> -
Compare with a value that type is
Output
or another Valuable -
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
onValuableChange(
) → void - Called when a Valuable notify a change.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unwatch(
Valuable valuable) → void -
Remove listener on the valuable, that may change scope, or that about to be disposed
Internal purpose
inherited
-
watch<
T> (Valuable< T> valuable, {ValuableContext? valuableContext, ValuableWatcherSelector<T> ? selector}) → T - Watch a valuable, that eventually change
Operators
-
operator <(
dynamic other) → Valuable< bool> -
Compare with a value that type is
Output
or another Valuable -
operator <=(
dynamic other) → Valuable< bool> -
Compare with a value that type is
Output
or another Valuable -
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator >(
dynamic other) → Valuable< bool> -
Compare with a value that type is
Output
or another Valuable -
operator >=(
dynamic other) → Valuable< bool> -
Compare with a value that type is
Output
or another Valuable
Static Methods
-
listenableComputed<
L extends Listenable, Output> (L listenable, Output computation(L listenable)) → Valuable< Output> - Factory Valuable.listenableComputed to build a Valuable that listen to a Listenable and provide a value by computation