-
-
Notifications
You must be signed in to change notification settings - Fork 942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add exception handling to 'ref.refresh()' #3682
Comments
There's nothing wrong with the future throwing IMO. You're not even awaiting it. Why does that matter? |
Thanks... Uncaught exceptions in callbacks are forwarded to the PlatformDispatcher (link). If these are not handled properly, such “errors” are logged for no reason. |
There is an error in your code afterall. Why would we want to silence it? |
Yes, the error is that the rebuild of the provider failed, e.g. due to a failed network request. This is logged by provider observer or the network service. However, since |
This isn't up to You could make a wrapper around it: class MyIndicator extends StatelessWidget {
Future<void> Function() onRefresh;
build(ctx) {
return RefreshIndicator(onRefresh: () => onRefresh()..ignore(), child: child);
}
} |
Hi @rrousselGit, thank you for taking your time and reviewing this feature request. I understand that this is not a critical issue. Maybe some people also rely on refresh to return a value. For me, its usage was always for (async) callbacks. Feel free to close this. Some suggestions:
|
Is your feature request related to a problem? Please describe.
#3651
Describe the solution you'd like
Here is how riverpod currently recomments implementing a pull to refresh.
However, this leads to an exception at the UI level if reading the updated value fails. The “ref.refresh()” function should take care of this.
Instead of returning a value,
ref.refresh()
should be handled similarly to a mutation that is watched byref.watch(provider)
and can be listened to byref.listen(provider)
. Therefore, it does not need to return an actual value, but indicate when the operation has finished (seeRefreshIndicator.onRefresh
).Options:
ref.refresh()
should return aFuture<void>
/void
/FutureOr<void>
ref.refresh()
returns avalue?
only containing avalue
if the refresh was successfulthrowOnError
toref.refresh()
Describe alternatives you've considered
Users should implement their own exception handling. But this needs to be explicitly mentioned in the API reference. Also, the examples in the documentation should be updated accordingly.
The text was updated successfully, but these errors were encountered: