intelligencezuloo.blogg.se

Flutter scaffold bottomnavigationbar
Flutter scaffold bottomnavigationbar









To make this possible, we only needed a few ingredients: Note how the counter value is preserved when switching between tabs Here’s what the end result looks like: Stateful nested navigation example. Stateful nested navigation “just works”, and each branch remembers its own state (all the pages inside each tab).

flutter scaffold bottomnavigationbar

  • We can easily switch between tabs (using navigationShell.goBranch) by writing only stateless code.
  • Stateful Nested Navigation: SummaryĪs it turns out, the code above already solves these problems: That’s because all the stateful logic lives inside the StatefulNavigationShell class itself - a widget that manages the state of a StatefulShellRoute, by creating a separate Navigator for each of its nested branches.

    #FLUTTER SCAFFOLD BOTTOMNAVIGATIONBAR UPDATE#

    What’s great about using navigationShell is that we don’t have to store and update any state (such as the selected index) inside our ScaffoldWithNestedNavigation (which is a StatelessWidget).

  • call the goBranch method so we can switch to a new branch when a new destination is selected.
  • retrieve the currentIndex that we can pass to the NavigationBar.
  • currentIndex, destinations: const, onDestinationSelected: _goBranch, ), )

    flutter scaffold bottomnavigationbar

    Scaffold ( body: navigationShell, bottomNavigationBar: NavigationBar ( selectedIndex: navigationShell. settings )), ], onDestinationSelected: ( index ) Īs we can see, the navigationShell is passed directly to the body of the Scaffold:

    flutter scaffold bottomnavigationbar

    home )), NavigationDestination ( label: 'Section B', icon: Icon ( Icons. Scaffold ( body: /* TODO: decide which page to show, depending on the selected index */, bottomNavigationBar: NavigationBar ( selectedIndex: /* TODO: where does this come from? */, destinations: const widget NavigationDestination ( label: 'Section A', icon: Icon ( Icons.









    Flutter scaffold bottomnavigationbar