-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
copied from csells/go_router#134
Currently there is no automatic way to have your routes remember their internal state as you navigate between them. This is often a desired UX feature as it is seen commonly on mobile and desktop platforms. For example, when I change tabs in a desktop app like Steam, it remembers my scroll position and selected sorting features (ephemeral view state).
The canonical way to do this in flutter is to use an Offstage widget, or something that wraps one, like an IndexedStack. The classic "nested navigator" pattern is a variation on this technique, where multiple stateful navigators are kept in memory using a TabBarView or IndexedStack.
I'm not sure if this is even possible with GoRouter, but would like to put this idea out there.
This is the core problem to solve. Given:
routes: [
GoRoute(path: 'page1', pageBuilder: (_, state) => MaterialPage(key: state.pageKey, child: Page1())),
GoRoute(path: 'page2', pageBuilder: (_, state) => MaterialPage(key: state.pageKey, child: Page2())),
]When page1 is the path, the result of () => MaterialPage(key: state.pageKey, child: Page2()) is stashed Offstage somehow. Vice versa when `page2 is rendered. It wouldn't load everything at once, but rather lazy load and "remember" pages it had seen before. Likely there should be an option to opt-out certain views for persistence.