Replies: 2 comments
-
The problem is that the My scenario is that when the user adds a new item, I'd prefer to just have the UI reset back to what happens when it first loads. |
Beta Was this translation helpful? Give feedback.
-
You generally shouldn't try to clear the "data" of an AsyncValue. Instead, prefer having your UI check |
Beta Was this translation helpful? Give feedback.
-
When refreshing a
FutureProvider
usingref.refresh
, it keeps the previous state while the asynchronous process is running. For example, if the previous state is anAsyncData
,ref.refresh
changes the provider's state toAsyncData(isLoading: true)
, not toAsyncLoading
. This behavior makes sense for cases like pull-to-refresh actions (showing old values while loading).However, there are some cases where this behavior is not ideal. For instance, when recovering from an error state such as a network connection failure, we might want to restart the provider from the
AsyncLoading
state rather than keeping the old error state. ForNotifier
s, we can manually achieve this as follows:This approach works well for
Notifier
s, but it's a bit tedious and doesn't work forFutureProvider
s. Is there a more efficient way to implement this restarting behavior?Thank you.
Beta Was this translation helpful? Give feedback.
All reactions