Skip to content

Navigator.pushReplacement() not working on confirm button tap #42

@talukdaranjan

Description

@talukdaranjan
ListTile(
                          iconColor: Colors.white,
                          textColor: Colors.white,
                          leading: Icon(Icons.logout_outlined),
                          title: Text("Logout"),
                          onTap: () {
                            CoolAlert.show(
                                context: context,
                                type: CoolAlertType.confirm,
                                title: 'Logout',
                                text: 'Are you sure you want to logout?',
                                confirmBtnText: 'Yes',
                                confirmBtnColor: Colors.red,
                                cancelBtnText: 'No',
                                closeOnConfirmBtnTap: true,
                                onConfirmBtnTap: () async {
                                  _prefs.setString(Prefs.adminUser, '');
                                  _prefs.setBool(Prefs.isLoggedIn, false);
                                  Navigator.pushReplacement(
                                      context,
                                      MaterialPageRoute(
                                          builder: (context) => Login()));
                                });
                          },
                        )

Above is the code snippet from my app. When the 'Yes' button is clicked, it erases the SharedPreference data, but not navigates to the Login Screen. Why?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions