2

I am currently using persistent_bottom_nav_bar: ^4.0.2 and rflutter_alert but the problem is when I call Navigator.of(context).pop(); I always get this error:

FlutterError (This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.)

That happens when I use persistent_bottom_nav_bar, I have tried to use bottomNavigationBar which is a property of Scaffold widget, and that's really fine and there is no problem with Navigator.of(context).pop();. Is there a way to do Navigator pop when using persistent_bottom_nav_bar

wahyu
  • 1,679
  • 5
  • 35
  • 73

3 Answers3

3

This worked for me.

 Alert(
      context: context,
      type: AlertType.error,
      title: "RFLUTTER ALERT",
      desc: "Flutter is more awesome with RFlutter Alert.",
      buttons: [
        DialogButton(
          child: Text(
            "COOL",
            style: TextStyle(color: Colors.white, fontSize: 20),
          ),
          onPressed: () => Navigator.of(context, rootNavigator: true).pop(),
          width: 120,
        )
      ],
    ).show();
Nabin Dhakal
  • 1,949
  • 3
  • 20
  • 48
0

I have found the solution after reading this discussion: https://github.com/RatelHub/rflutter_alert/issues/20#issuecomment-535330620. So, instead of using Navigator.of(context).pop(); I change it to Navigator.of(context, rootNavigator: true).pop()

wahyu
  • 1,679
  • 5
  • 35
  • 73
0

Try to use:

    Navigator.pop(context);
Abdelrahman Tareq
  • 1,874
  • 3
  • 17
  • 32