Reputation: 5532
Problem description:
The code is as follows
@riverpod
Future<String> getUserInfo(GetUserInfoRef ref) async {
ResponseModel res = await TestApi.getUserInfo();
return res.data['name'];
}
// UI Page
Widget build(BuildContext context) {
final request = ref.watch(getUserInfoProvider);
return Scaffold(
appBar: AppBar(title: const Text("MyPage2")),
body: switch (request) {
AsyncData(:final value) => Text(value),
AsyncError(:final error) => MyErrorWidget(
onReload: () {
// Reload button click callback
ref.refresh(getUserInfoProvider);
},
),
_ => const CircularProgressIndicator(color: Colors.red),
},
);
}
I tried refreshing the provider, but it didn't work. I hope there is a way to make the provider state start from loading when refreshing the provider. Otherwise, I can only add a loading widget in MyErrorWidget to handle it.
Upvotes: 0
Views: 132
Reputation: 1326
I would recommend having a look at the riverpod documentation showing how to implement pull to refresh.
In the example mentioned above, to refresh a FutureProvider:
onRefresh: () => ref.refresh(getUserInfoProvider.future),
is used.
Upvotes: 1