In flutter, I’m on one Widget and there is logout functionality. So once I click on it I want to remove all other widget’s instance from the Widget tree and jump on logout widgets, so what I need to use?
TextButton.icon(
label: const Text('Logout'),
icon: const Icon(Icons.logout),
onPressed: () {
Provider.of<Auth>(context, listen: false).logout();
Navigator.pushAndRemoveUntil(
context,
ModalRoute.withName(AuthScreens.routeName) as Route<Object>,
(route) => false,
);
},
)
2
Answers
So I was using wrong approached there. Basically, I was ignoring the it's parameter's Type value, which should be only Route to String.
with this changes I solved the issue, You can compared my previous code and this code, you will find the proper different in it.
You may have to use
popUntil
Or if you are popping and pushing to new page then
Here,
NewPage
represents the page which user to be navigated after logout.(E.g:RegistrationPage()
)