Lazy<T> class

A Lazy can be used to only initialize a value if it is required.

The _initialize function is only called to initialize the value. After the first initialization _initialize is only called again if one of the following cases applies:

  • reinitializeOnValue returns true
  • the last invocation of _initialize has thrown an error and reinitializeOnError is true
  • invalidate was called after the last but before the current call to get

If the first get call is still in progress, any subsequent call to get will wait for the result of the first invocation and return the same result.

If _initialize throws an exception every call to get will re-throw this exception.

Constructors

Lazy(FutureOr<T> _initialize(), {FutureOr<bool> reinitializeOnValue(T value)?, bool reinitializeOnError = false})
_initialize is used to initialize the value. reinitialize controls if a value is reused or initialized again. If reinitialize returns true, _initialize is called again to recreate the value.

Properties

hashCode int
The hash code for this object.
no setterinherited
isInitialized bool
Returns true if the this Lazy already has a result.
no setter
reinitializeOnError bool
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

get() Future<T>
Receives the value returned by initialize.
invalidate() → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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