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);
}
}