如何使用 Riverpod 更新 FutureProvider 中的值?

Nid*_*hal 6 dart flutter riverpod

我有一个带有项目列表的 FutureProvider。如何在不刷新提供程序的情况下更新此列表中的项目?

小智 2

您应该为您的列表使用 StateNotifierProvider,如下所示:

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
  }
}
Run Code Online (Sandbox Code Playgroud)

在此之前,请填写您listProvider未来的回复。您还应该将dynamic类型更改为列表中的对象类型