flutter_cool_alert icon indicating copy to clipboard operation
flutter_cool_alert copied to clipboard

Navigator.pushReplacement() not working on confirm button tap

Open talukdaranjan opened this issue 2 years ago • 4 comments

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?

talukdaranjan avatar Dec 20 '23 13:12 talukdaranjan

I have same issue. Did you find solution for it?

aolmez avatar Jan 26 '24 15:01 aolmez

I have same issue. Did you find solution for it?

No. I have used another library for the same.

talukdaranjan avatar Jan 27 '24 07:01 talukdaranjan

I also have the same issue... It seems it's a bug of some sort

ricardomud avatar May 20 '24 15:05 ricardomud

This issue occurs because the dialog is still on the screen when you try to navigate. Adding a delay of a few milliseconds before navigating provides a workaround.

mohammedjavadkt avatar Aug 17 '24 10:08 mohammedjavadkt