getx
getx copied to clipboard
Get nearest nested navigator key?
Hi, I’m trying to implement the following scenario with GetX navigation:
a) on mobile, all navigation is happening inside root navigator (i.e. each screen is just a fullscreen page)
b) on desktop, two panes, second pane has nested Navigator (id: Get.nestedKey(1)
), so the nested pages and subsequent nagivation should be happening there.
Now, inside the nested screen I need to provide navigator id
to Get.to() call. On mobile, that would be the null
, on desktop = Get.nestedKey(1).
Is there a way for Get.to() to simply use nearest navigator? Or somehow get nearest navigator key and provide it to Get.to? Currently the only option I can see is to pass «current id» to all screens, or somehow store it the state, which seems to be overkill.
You can either create a navigator key or use Flutter's Navigator API
@iandis the question is whether Get.to() can automatically choose the nearest navigator.
Desktop: RootNavigator
- Navigator1
- Navigator2
-
Get.to()
call
-
- Navigator2
Mobile: RootNavigator
- Navigator1
-
Get.to()
call
-
How to make Get.to to choose automatically Navigator2
in the first case, and Navigator1
in the second?
It simply can't. You need BuildContext