错误:在小部件树中检测到重复的 GlobalKey

时间:2021-03-29 15:48:35

标签: flutter dart flutter-navigation

当我将其作为我开发的应用程序中的注销部分再次发送到登录屏幕时,出现此错误。

在小部件树中检测到重复的 GlobalKey。

我的注销方法如下。我需要处理全局密钥吗?你能帮我吗?

Navigator.of(context).push(
                MaterialPageRoute(builder: (BuildContext context) => Yoklama()),
              );

1 个答案:

答案 0 :(得分:0)

也许你应该试试这个

Navigator.pop(context);

发生这种情况是因为您的登录屏幕没有关闭,而您在单击注销时试图重新打开它。

如果上面的代码对你不起作用,那么试试这个。

当您登录时,请使用此导航器:

  Navigator.of(context).pushReplacement(
          MaterialPageRoute(builder: (BuildContext context) => YourHomePageScreen()),
        );

当你注销然后使用这个

Navigator.of(context).pushReplacement(
                MaterialPageRoute(builder: (BuildContext context) => Yoklama()),
              );