getx icon indicating copy to clipboard operation
getx copied to clipboard

Get nearest nested navigator key?

Open divan opened this issue 2 years ago • 3 comments

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.

divan avatar Jul 24 '22 20:07 divan

You can either create a navigator key or use Flutter's Navigator API

iandis avatar Aug 06 '22 22:08 iandis

@iandis the question is whether Get.to() can automatically choose the nearest navigator.

Desktop: RootNavigator

  • Navigator1
    • Navigator2
      • Get.to() call

Mobile: RootNavigator

  • Navigator1
    • Get.to() call

How to make Get.to to choose automatically Navigator2 in the first case, and Navigator1 in the second?

divan avatar Aug 08 '22 11:08 divan

It simply can't. You need BuildContext

iandis avatar Aug 08 '22 17:08 iandis