AsyncValueIsLoadingException class
AsyncValue.requireValue was called on an AsyncValue with no error nor a value.
Chaining asynchronous providers synchronously.
When AsyncValueIsLoadingException (thrown by requireValue during loading states)
is thrown within a provider's initialization,
Riverpod will silence it.
Combined with the fact that Ref.watch rebuilds a provider when the dependency
changes, this enables combining asynchronous providers in a synchronous manner.
The following example adds two numbers obtained asynchronously, in a synchronous manner. This ensures that within the same frame where one of those asynchronous providers updates, the sum is immediately updated.
// We use FutureProvider + AsyncValue to sycnhronously combine asynchronous providers.
// Notice how the callback of FutureProvider is not marked as async.
final sumProvider = FutureProvider<User>((ref) {
AsyncValue<int> value = ref.watch(someProvider);
AsyncValue<int> anotherValue = ref.watch(anotherProvider);
return value.requireValue + anotherValue.requireValue;
});
Note that this usage is only valid within providers that are expected to create a FutureOr (cf FutureProvider/AsyncNotifierProvider).
- Implemented types
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
value
→ AsyncValue<
Object?> -
The AsyncValue that was in loading state when AsyncValue.requireValue was called.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited