-
I'm trying out go_router with riverpod, and I was wondering on how to get a Listenable from a riverpod provider. I'm currently using ChangeNotifier and it works fine, but I want to use StateNotifier instead and I don't know how to make it work. Any suggestions on how I can make Repo link: App sample file: root_screen.dart
file: auth_state_notifier.dart
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You handle the simple boolean state. Your class AuthStateNotifier extends StateNotifier<bool>{
AuthStateNotifier() : super(false);
void authenticate() {
state = true;
}
void logout() {
state = false;
} |
Beta Was this translation helpful? Give feedback.
-
My state class looks like this. I am using freezed union for this. How do handle the routing flow based on the authentication state? I my project, oAuth2 is used so that when pressing the login button it opens a webview (modally on iOS). If the user cancels the webview, then authentication fails and the state becomes unauthenticated, and I need to show a failure alert. |
Beta Was this translation helpful? Give feedback.
You handle the simple boolean state. Your
StateNotifier
should look like this: