Milad-Akarie / auto_route_library

Flutter route generator
MIT License
1.58k stars 400 forks source link

Sharing state between tabs #968

Closed AAverin closed 2 years ago

AAverin commented 2 years ago

I have this flow

    AutoRoute(page: GuideScreen, path: "/guide/:id", children: [
      AutoRoute(path: "overview", page: OverviewPage),
      AutoRoute(path: "spots", page: SpotsPage),
      AutoRoute(path: "map", page: MapPage),
      AutoRoute(path: "allSpotsGallery", page: AllSpotsGallery)
    ]),

Guide screen loads guide inside it and guide is supposed to be shared between all tabs. With Navigator 1.0 what I was doing is just changing the selected page when route was triggered. Now with AutoTabsScaffold it looks like triggering a new route doesn't just change the page, but also expect all the parameters to be passed to the route.

The exact use case is:

What would be a good way to share GuideData between the tabs while still navigating with the Router and deeplinks? Imaginable solution:

Milad-Akarie commented 2 years ago

Hello @AAverin my first thought would be providing the GuidDate inside of GuidScreen through context using Provider, inherited state or such, so you have access to it anywhere down the widgets tree.

AAverin commented 2 years ago

@Milad-Akarie Looks like the only way to go is to make sure routes don't have parameters and share all the data some other way?

github-actions[bot] commented 2 years ago

Stale issue message