我有一个简单的页面,其中显示了一个产品,我正在尝试使用riverpod和futureprovider,但未来只在我第一次访问该页面时才被称为?
final productInfo = FutureProvider<Map<String, dynamic>>((ref) async {
final response =
await http.get('https://www.api.com/$clickedID');
final content = json.decode(response.body) as Map<String, dynamic>;
return content;
});发布于 2021-09-21 15:14:28
使用最新的Riverpod,您可以执行ref.refresh(userProvider)来刷新提供程序。
发布于 2020-12-13 01:19:06
请使用
final userProvider = StreamProvider<User>(
final response =
await http.get('https://www.api.com/$clickedID');
final content = json.decode(response.body) as Map<String, dynamic>;
return content;
);现在,您可以使用watch监听提供者,
AsyncValue<User> user = watch(userProvider);发布于 2021-02-10 16:34:57
没有内置功能,但您可以在以后使用相同的将来重写该值。
recallProductInfoFutureProvider() {
final response = http.get('https://www.api.com/$clickedID');
final content = json.decode(response.body) as Map<String, dynamic>;
productInfo.overrideWithValue(content)
}考虑使用StreamProvider和观看内部消费者来更新overrideWithValue上的UI。
https://stackoverflow.com/questions/65267606
复制相似问题