Riverpod AsyncNotifier doesn't reset the variables in notifier after ref.invalidate

233 Views Asked by At

There is a scenario in which I need to invalidate/refresh my AsyncNotifier to start fresh, but when I invalidate it I face 2 issues:

  1. I have a variable inside my AsyncNotifier class that after invalidating that provider still holds on to the data that it had before invalidation, then how should I invalidate a provider to make it refresh everything including variables locally in that class?
  2. It still returns AsyncData but changes the isLoading into true, but I thought it should set data null and then start the build function, am I wrong? I'd appreciate it a lot if you could help me!
1

There are 1 best solutions below

0
On

Calling ref.invalidate will reset the visible state to AsyncLoading, but the AsyncValue holds "prior" status in some cases for seamless transitions. If you use the default .when, it will go seamlessly from the old value to the new value once the new value is built. If you want to go back to loading state in between, either add the appropriate flag to .when, or use an explicit pattern match on AsyncLoading vs AsyncData.