How to preserve widget states in flutter, when navigating using BottomNavigationBar?

后端 未结 6 1437
青春惊慌失措
青春惊慌失措 2020-11-27 12:20

I\'m currently working on building a Flutter app that will preserve states when navigating from one screen, to another, and back again when utilizing BottomNavigationBar. Ju

6条回答
  •  爱一瞬间的悲伤
    2020-11-27 13:10

    Use “IndexedStack Widget” with “Bottom Navigation Bar Widget” to keep state of Screens/pages/Widget

    Provide list of Widget to IndexedStack and index of widget you want to show because IndexedStack show single widget from list at one time.

    final List _children = [
        FirstClass(),
        SecondClass()
      ];
    
    Scaffold(
      body: IndexedStack(
        index: _selectedPage,
        children: _children,
      ),
      bottomNavigationBar: BottomNavigationBar(
        ........
        ........
      ), 
    );
    

提交回复
热议问题