Wrapping Nested Navigator Content Is Not IndexedStack
So all over the place you see wrapping nested navigator content in an IndexedStack. Even GoRouter covers it with their own index method. Let me clue you in, PageView and IndexedStack can only be used for light widget trees due to the increases in memory of keeping that many pages in memory.
That means it has only limited uses such as the small mobile device form. But what about saving the state of the screen when navigating to another screen? The savior is the PageStorageKey construct:
class _HomePageState extends State<HomePage> { .... final PageStorageBucket _bucket = PageStorageBucket(); final screens = [ const ScreenA( key: PageStorageKey<String>('Screen-A'), ), const ScreenB( key: PageStorageKey<String>('Screen-B'), ) ]; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: PageStorage(bucket: _bucket, child: screens[_selectedIndex]), bottomNavigationBar: BottomNavigationBar( currentIndex: _selectedIndex, onTap: onTap, items: bottomNavigationBarItems ), ), ); } }
Why is this important? Because Google still has not detailed the Adaptive Scaffold and Canonical Layouts in the Flutter SDK docs or the codelabs. And, because I am offering that full solution as one of my paid substack subscriber gifts:
Expected delivery of that gift is about 25 days from now.