Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have got my homepage from which I can go to profile page in my flutter application. On profile icon pressed, I push my context to profile page where I have a button to change password. When I press the change password, it opens an alert dialog which has textfield to enter password. I have a function logout which logs out of the application by clearing preferences and pushing context to login screen as replacement. Now I want to logout of my application when I change the password. But it pushes replacement to the top of the navigation stack which returns login page within the stack. How do I resolve this issue?
_changePassword() async{
print(widget.id);
var data = {
"newPassword": _passcontroller.text,
"confirmNewPassword": _confirmpasscontroller.text
var res = await CallApi().putData(data, 'users/${widget.id}/password/change');
var response = res.data;
print(response);
if (response['success']) {
showSimpleFlushbar(context, 'Password Changed Successfully.');
logout(context);
It removes previous all navigations and brings you to landing page(first page).
()=> Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (BuildContext context) => LoginPage()),
ModalRoute.withName('/'),
it will remove previous whole navigations.
//Use this for logout
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (BuildContext context) => LoginPage()),
(Route<dynamic> route) => false
Navigator.of(context).pushNamedAndRemoveUntil('/landingpage', (Route<dynamic> route) => false);
Use this code for removing whole navigation stack in flutter
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context) =>
ClassName()), (Route<dynamic> route) => false);
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.