Search code examples
flutterdartflutter-dependenciesriverpod

How to refresh all providers in Riverpod


When user logout's from the app, I want to refresh all providers so that the previous user's data will not be stored on current users providers. Is there a global way to do this without using autodispose or ref.invalidate(provider) ?


Solution

  • You need one provider who is responsible for authorization (bool|false). All other providers watch it using ref.watch or ref.listen. As soon as the user logs out, the providers will rebuild themselves.