如何在 Flutter 中获取当前路由路径? [英] How to get current route path in Flutter?

查看:31
本文介绍了如何在 Flutter 中获取当前路由路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实现持久底栏时,之前的路由需要恢复 底部栏被点击.

While implementing persistent bottom bar, previous route need to be restored when a button in the bottom bar was clicked.

当点击底部栏中的按钮时,其当前路由路径(/a/b/c) 被保存,并根据按钮点击恢复之前保存的路线.

When a button in the bottom bar is clicked, its current route path (/a/b/c) is saved and previously saved route is restored according to the button click.

从概念上讲,用户会将每个按钮视为一个工作区,并且其状态永远不会丢失(包括返回堆栈).用户可以安全地从一个工作区切换到另一个工作区.

Conceptually user will think each button as a workspace and its state is never get lost (including back stack). User can safely switch from one workspace to another.

当路由 rewinding to root 时如何在 Flutter 中获取当前路由路径?

推荐答案

这应该给你确切的路线名称

This should give you the exact route name

ModalRoute.of(context).settings.name

如果您使用 Navigator.popuntil .. 检查 Rémi Rousselet 的其他答案 https://stackoverflow.com/a/50817399/5921185

if you use Navigator.popuntil.. check this other answer out by Rémi Rousselet https://stackoverflow.com/a/50817399/5921185

这篇关于如何在 Flutter 中获取当前路由路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆