Cyrus the Great
Cyrus the Great

Reputation: 5942

Riverpod: call async riverpod inside other provider

I am using Riverpod in my project, in one of my providers I want to call another async provider, SO this is my code:

@riverpod
class SelectedUser extends _$SelectedUser {
  
  @override
  List<UserModel> build() {
    return [];
  }

  void setSelectedUser(....) async {

 ref.watch(usersProvider).whenData((users) {
      //noting return back
     
      state = selectedUser;
    });

but When data never is called, I am sure the data in userProvider is returned but here, when data is never called. What is the issue? Is the correct way to call another provider inside another one?

When I am using final users = await ref.watch(usersProvider.future); I receive the result but whenData No.

Upvotes: 1

Views: 282

Answers (1)

Cucumber and Melon
Cucumber and Melon

Reputation: 1

ref.watch(statusesProvider).when(
    data: (users) {
      state = AsyncValue(users);
    },
    loading: () {},
    error: (_, __) {
      state = AsyncValue([]);
    });

Upvotes: 0

Related Questions