EnsureInitializedResult<T> mixin
A mixin that allows to track whether the object is ready for usage.
Sometimes it is nice to wait for some heavy initialization process before using the object. Instead of implementing some kind of booleans, we can use futures instead.
Example:
class SomeClass with EnsureInitialized<int> {
SomeClass() {
_init();
}
Future<int> _heavyComputations() async {
await Future.delayed(const Duration(seconds: 5));
return 0;
}
Future<void> _init() async {
try {
final result = await _heavyComputations();
initializedSuccessfully(result);
} on Exception catch (e, s) {
unableToInitialize(e, s);
}
}
}
- @Deprecated('Use EnsureInitializedResultMixin instead')
Properties
-
ensureInitialized
→ Future<
T> -
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
initializedSuccessfully(
T result) → void - The method that marks the object has been initialized successfully.
-
initializedWithError(
{Object? error, String? message, StackTrace? stackTrace}) → void - The method that marks the object was initialized with an error.
-
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