Need a persistent/same Bottom Navigation Bar for all screens - Flutter

前端 未结 9 1099
不思量自难忘°
不思量自难忘° 2021-02-01 21:50

I am a beginner with flutter and dart. I have been trying to implement a navigationBar on three different pages in my app. The toggling works well for an individual

9条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-01 22:25

    I created a small, super easy to use package that let you do that effect CustomNavigator. And wrote a tutorial about it on Medium you can find it here.

    So it goes like this

    // Here's the custom scaffold widget
    // It takes a normal scaffold with mandatory bottom navigation bar
    // and children who are your pages
    CustomScaffold(
      scaffold: Scaffold(
        bottomNavigationBar: BottomNavigationBar(
          items: _items,
        ),
      ),
    
      // Children are the pages that will be shown by every click
      // They should placed in order such as
      // `page 0` will be presented when `item 0` in the [BottomNavigationBar] clicked.
      children: [
        Page('0'),
        Page('1'),
        Page('2'),
      ],
    
      // Called when one of the [items] is tapped.
      onItemTap: (index) {},
    );
    

    The cool thing about this library that it works efficiently. It creates a nested navigator (which is very unpleasant to do) and uses it for navigation in your widget tree. And of course you can always use the default navigator from MaterialApp

提交回复
热议问题