返回到 flutter 中查看
我在颤振中的导航器有一个小问题。我有 3 个窗口:(登录 -> 主页 -> 订单)。但是,当我从“登录”转到“主页”时,一切正常,但如果我从“主页”转到“订单”并使用 android 后退按钮,它会将我返回到“登录”窗口,即直到第一个视图,而不是第二个视图。
登录的我的代码导航:
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => HomeScreen(),
),
);
HomeScreen 的我的代码导航
Navigator.push(this.context,
MaterialPageRoute(
builder: (context) =\> Orders(
numTable: numTable,
),
)
);
i have a little problem with the Navigator in flutter. I have 3 windows: (Login -> Home -> Orders). But when I go from Login to Home, everything works fine, but if I go from Home to Orders and use the android back button, it returns me to the Login window, that is, until the first view, not the second.
My code Navigation of Login:
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => HomeScreen(),
),
);
My Code Navigation of HomeScreen
Navigator.push(this.context,
MaterialPageRoute(
builder: (context) =\> Orders(
numTable: numTable,
),
)
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
解决方案:在登录页面使用pushAndRemoveUntil或pushReplacement
Solution : use pushAndRemoveUntil or pushReplacement at the LoginPage
中使用Login pushReplacement,
如果用户登录成功,在HomeScreen
当点击android后退按钮时,将转到窗口HomeScreen
if users login successfully use in Login pushReplacement
in HomeScreen
when click android back button will go window HomeScreen
您可以按照这种方法执行您想要的操作,只需在每个页面上执行 Navigator.of(context).push(route) 即可:
You can follow this approach which does what you want, just do Navigator.of(context).push(route) on each page:
尽管使用 Material 包中的 Navigator 可以回答您的问题,但我想为您提供一个在 Flutter 中更简单导航的提示:使用 获取包。
使用 Get,此代码:
可以替换为此代码:
在您的示例中,当用户经过身份验证时,您将使用以下代码从登录转到主页:
之后,您可以像这样从一个屏幕移动到另一个屏幕:
Although there are answers to your question using the Navigator from the Material package, I would like to provide you with a tip for much simpler navigation in Flutter: Use the Get package.
With Get, this code:
can be replaced with this code:
In your example, you will then use the following code to go from Login to Home when a user has been authenticated:
After that, you can move from screen to screen like this: