Hello, I am using your login example.
I have this Pages and each Page push the other using Navigator.of(context)...
HomePage
---- OtherPage
-------- SomeOtherPage
------------ LogoutPage
I call the authenticationBloc.dispatch(LoggedOut()) in LogoutPage and the only page that are closed is HomePage, the other three pages are still in screen :(
thanks
@basketball-ico great question! Since you've pushed all of these pages onto the navigation stack you'll have to pop them off when you dispatch the LoggedOut event.
Otherwise what's happening is the root view is getting updated based on the AuthenticationState but OtherPage, SomeOtherPage, and LogoutPage are still on top of the Navigation stack.
You can use Navigator.popUntil(context, ModalRoute.withName(Navigator.defaultRouteName)) if you are using MaterialPageRoute to pop off all views except the default.
Does that help?
Thanks, that works, but I need to call Navigator.popUntil(context, ModalRoute.withName(Navigator.defaultRouteName)) only when the state are AuthenticationUnauntheticated, because when dispatch(LoggedOut()) This event do some things, and only set Unauntheticated state when not have errors.
Other scenario is in register form, i need call the popUntil only when the user is sucessful registrered.
How? :(
Thanks
You can probably just do something like:
// BlocBuilder in root page with AuthenticationBloc
builder(context, state) {
if (state is Unauthenticated) {
SchedulerBindings.instance.addPostFrameCallback((_) {
Navigator.popUntil(context, ModalRoute.withName(Navigator.defaultRouteName));
});
// return LoginForm or other unauthenticated widget
}
}
within the BlocBuilder at the default route. That way whenever authentication state changes you don't have to worry about popping from all locations. Does that help?
Thanks,
Perfect, that is that I was searching. 馃帀馃帀馃帀
Most helpful comment
Thanks,
Perfect, that is that I was searching. 馃帀馃帀馃帀