英文:
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});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论