如何在Flutter中返回两页前。

3

现在我正在尝试删除数据,当我完成删除后,页面应该返回到主页。问题是当我使用导航器回到主页时,user_id返回null而不是真实的user_id。我该如何管理内容的流程?

我用以下代码返回前两个页面。

 new RaisedButton(
      child: new Text("OK DELETE!",style: TextStyle(color: Colors.black),),
      color: Colors.red,
      onPressed: (){
        deleteData();
        Navigator.of(context).push(
          MaterialPageRoute(
              builder: (BuildContext context)=> OwnerPage())
        );
      },
    ),

在删除之前的图像: enter image description here 在删除后的图像: enter image description here 附加信息。从登录页面到主页,我正在使用这种类型的代码: enter image description here
2个回答

2

有不同的方法来导航到不同的页面。不好的做法是使用Navigator.pop()两次。好的做法是需要添加参数:

  Navigator.of(context).push(
      MaterialPageRoute(
          builder: (BuildContext context)=> OwnerPage(username: username, user_id: user_id)) // Add parameters
    );

1
谢谢,它有效了。我喜欢你的坏主意,但好的方案正在运行中。(>.<) - Mohd Azwan

2
如果您正在使用路由来在页面之间导航,您可以这样做。
Navigator.pushNamed(context,'/OwnerPage');

这将直接导航到OwnerPage页面。

希望这对您有所帮助!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接