Get.toNamed 无法从底部表单 / 不同上下文中工作

huangapple go评论58阅读模式
英文:

Get.toNamed not working from bottom sheet / different context

问题

我想在嵌套的底部表单中使用Get.toNamed(从一个底部表单中调用的底部表单)。但是,它不起作用。我认为这是因为上下文不同。如果我使用Navigator,Navigator.of(context, rootNavigator: true).pushNamed("/route"); 这将起作用。但在我的情况下,我必须使用GetX路由,因为给定的路由正在从Get.arguments中获取参数。有没有任何方法让Get.toNamed工作?

英文:

I want to use Get.toNamed from a nested bottom sheet (bottom sheet called from a bottom sheet). However, it is not working. I think it's because the context is different. If I was using Navigator, Navigator.of(context, rootNavigator: true).pushNamed("/route"); this would work. However, in my case, I must use the GetX router because the given route is taking in arguments from Get.arguments. Is there any workaround to make Get.toNamed work?

答案1

得分: 1

以下是翻译好的内容:

"很难确定问题的所在,如果不查看您的代码。GetX 只是 Navigator 的一个包装器,所以两者都应该可以工作。

尝试

Get.offAndToNamed()"

英文:

It's hard to see where the problem is without looking at you code. GetX is just a wrapper around Navigator, so both should work.

Try

Get.offAndToNamed<void>()

答案2

得分: 0

我注意到 Get.arguments 可以读取参数,即使使用 Navigator 前往一个路由。所以我只是使用了 Navigator.of(context, rootNavigator: true).pushNamed('/home', arguments: {'tab': 2});

英文:

I realized that Get.arguments can read arguments even if Navigator was used to come to a route. So I just used Navigator.of(context, rootNavigator: true).pushNamed('/home', arguments: {'tab': 2});

huangapple
  • 本文由 发表于 2023年3月20日 22:32:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75791599.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定