how to use ref.listener's previous and next value? #969
-
I was user StateNotifier code:
In above code i am trying to put state for loading, error and success which will be used to show loading dialog for loading state, snackbar for error state and list of data for success state in previous version. Now it doesn't work as i will get Listener code:
Here what will happen is i will not get data in my listview as well as my dialogbox will keep showing. if i change above code to only listen for next state, i wont be able to show dialogbox as in next state it will never get So i would like to know if there is any example to use in my case for solve this problem? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You do want to listen only to "next" You can solve that by using a ConsumerStatefulWidget + initState by doing something like: initState() {
super.initState();
if (ref.read(mainCategoryViewModel) is ParentCategoryLoading) {
Future(() => showWaitingDialog(context));
}
} |
Beta Was this translation helpful? Give feedback.
You do want to listen only to "next"
Your issue is, by the time you call
ref.listen
, your notifier is already in loading state, so you won't receive the loading event.You can solve that by using a ConsumerStatefulWidget + initState by doing something like: