Search code examples
flutterdartriverpodflutter-riverpod

AsyncLoading VS AsyncValue.loading


I am trying to create Auth and Todo app. The problem is that I don't know which is the correct usage and don't know the difference between the two.

I want to use it before adding an item to the Todo List.

Is there a clear distinction between them, or do they have the same meaning?

I saw common.dart file but it written like this.

 /// Creates an [AsyncValue] in loading state.
  ///
  /// Prefer always using this constructor with the `const` keyword.
  // coverage:ignore-start
 const factory AsyncValue.loading() = AsyncLoading<T>;```

Solution

  • They are the same. AsyncData, AsyncError and AsyncLoading are just syntax sugar for different states of AsyncValue

    here is the implementation from the library, it is indeed the same.

      const factory AsyncValue.data(T value) = AsyncData<T>;
    
      const factory AsyncValue.loading() = AsyncLoading<T>;