Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit committed Aug 27, 2023
1 parent 2d65860 commit 1fb2172
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/riverpod/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,13 @@ abstract class AsyncValue<T> {
/// return null. While during error state, the error will be rethrown instead.
///
/// If you do not want to return previous value during loading/error states,
/// consider using [asData]:
/// consider using [unwrapPrevious] with [valueOrNull]:
///
/// ```dart
/// ref.watch(provider).asData()?.value;
/// ref.watch(provider).unwrapPrevious().valueOrNull;
/// ```
///
/// This will return null during loading/error states.
///
/// See also [valueOrNull], which does not throw during error state.
T? get value;

/// The [error].
Expand Down Expand Up @@ -551,7 +549,10 @@ extension AsyncValueX<T> on AsyncValue<T> {
bool get hasError => error != null;

/// Upcast [AsyncValue] into an [AsyncData], or return null if the [AsyncValue]
/// is in loading/error state.
/// is an [AsyncLoading]/[AsyncError].
///
/// Note that an [AsyncData] may still be in loading/error state, such
/// as during a pull-to-refresh.
AsyncData<T>? get asData {
return map(
data: (d) => d,
Expand All @@ -561,7 +562,10 @@ extension AsyncValueX<T> on AsyncValue<T> {
}

/// Upcast [AsyncValue] into an [AsyncError], or return null if the [AsyncValue]
/// is in loading/data state.
/// is an [AsyncLoading]/[AsyncData].
///
/// Note that an [AsyncError] may still be in loading state, such
/// as during a pull-to-refresh.
AsyncError<T>? get asError => map(
data: (_) => null,
error: (e) => e,
Expand Down

0 comments on commit 1fb2172

Please sign in to comment.