Replies: 1 comment
-
After a LONG night, I was able to work-around this behavior by manually transferring the page to the Home Screen prior to calling signout. This appears to work and the app now redirects back to the auth screen. onTap: () async {
Navigator.of(context).pushReplacementNamed(HomeScreen.routeName);
await auth.signOut(); // Here I call the Firebase signout
if (context.mounted) {
Navigator.of(context).pop();
}
}, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
m using Riverpod, Firebase and Flutter in a mobile app (iOS and Android) and ran into a weird behavior today. I'm flummoxed.
Background
Problem
The problem comes starts once I'm successfully signed in and visit my ThingListScreen that accesses the StreamProvider. If I open the app_drawer and click "Sign Out," once the ThingListScreen has already started watching the StreamProvider, main.dart doesn't redirect to the AuthScreen on signout. Main.dart hits the call to redirect but the screen doesn't switch over. Instead, the ThingListScreen runs its build() method again, AFTER main.dart has called
return const AuthScreen()
.I have confirmed that this doesnt happen on pages where Im not watching a StreamProvider from Riverpod.
It makes sense based on my code that the StreamProvider, which having also watched for authStateChanges, no longer has a user so it just calls return const Stream.empty().
It is puzzling to me that the thingListScreen is running it's build() method AFTER main.dart has already called for the transfer to AuthScreen(). I realize the user is still on the ThingListScreen() when the signout is triggered, but I would expect main.dart to immediately transfer over to the AuthScreen(), especially since that line of code is being executed first.
I have run the debugger and can verify the main.dart redirect to AuthScreen() is being called. Instead of transferring, however, the next thing that happens in the debugger is the ThingListScreen build() starts to run, which locks me into a ThingListScreen with an empty stream and no AuthScreen transfer.
Since this pattern seems to be pretty common (i.e. watching for authStateChanges in main.dart and immediately redirecting to an AuthScreen when the user is logged out from anywhere in the app), Im struggling to understand why its not happening in my case. Is there any way to prevent the rebuild from happening and instead just transfer over to AuthScreen()?
Any insights would be greatly appreciated!
global_providers.dart
main.dart
thing_list_screen.dart
app_drawer.dart
I expected that when the authStateChanges in main.dart, the user would immediately be redirected to the AuthScreen().
I tried to short circuit the build method in ThingListScreen by doing a forced manual redirection before the streamProvider has started being watched, like this:
and that does force the redirect. However, when I log in again, the app doesn't redirect to the HomeScreen and instead transfers back to the page that was up when I logged out. This feels like a poor solution since I would have to put this conditional check on every single page from which I could logout. It also seems to defeat the purpose of having main.dart manage the redirect on authStateChanges.
Beta Was this translation helpful? Give feedback.
All reactions