简体   繁体   English

使用 persistent_bottom_nav_bar 时导航器弹出 - Flutter

[英]Navigator pop when using persistent_bottom_nav_bar - Flutter

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();我目前正在使用persistent_bottom_nav_bar: ^4.0.2rflutter_alert但问题是当我调用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();当我使用persistent_bottom_nav_bar时会发生这种情况,我尝试使用bottomNavigationBar这是Scaffold小部件的属性,这真的很好,而且Navigator.of(context).pop();没有问题. . Is there a way to do Navigator pop when using persistent_bottom_nav_bar使用persistent_bottom_nav_bar时有没有办法做 Navigator pop

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

I have found the solution after reading this discussion: https://github.com/RatelHub/rflutter_alert/issues/20#issuecomment-535330620 .阅读此讨论后,我找到了解决方案: https://github.com/RatelHub/rflutter_alert/issues/20#issuecomment-535330620 So, instead of using Navigator.of(context).pop();因此,不要使用Navigator.of(context).pop(); I change it to Navigator.of(context, rootNavigator: true).pop()我将其更改为Navigator.of(context, rootNavigator: true).pop()

Try to use:尝试使用:

    Navigator.pop(context);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM