How can I update the value in FutureProvider with riverpod?

Viewed 567

I have a FutureProvider with a List of items. How can I update an item in this list without a refresh the provider?

1 Answers

You should use a StateNotifierProvider for your list like this:

final listProvider = StateNotifierProvider<ListItem, dynamic>((ref) {
  return ListItem([]);
});

class ListItem extends StateNotifier<dynamic> {
  ListItem(List<dynamic> items) : super(items);
  void update(dynamic item) {
     // Your update logic. You have access to the use with 'state' variable
  }
}

Before that you populate the listProvider with your future response. Also you should change the dynamic type to your object type on the list

Related