Search code examples
javaflutterdarterror-handlinghelper

How can i fix the bottom navigator error in dart


I was making a BottonNavigation bar in flutter dart and i am getting an error

the code is This the code

enter image description here

the error is And this the error pls help

enter image description here

I want a solution for this error if someone can help me i will thank them a lot

The console version is this


Solution

  • you need to pass NavigationDestination instead of NavigationDrawerDestination in the destinations params

    ** sample code snippet **

    bottomNavigationBar: NavigationBar(
            onDestinationSelected: (int index) {
              setState(() {
                currentPageIndex = index;
              });
            },
            selectedIndex: currentPageIndex,
            destinations: const <Widget>[
              NavigationDestination(
                icon: Icon(Icons.explore),
                label: 'Explore',
              ),
              NavigationDestination(
                icon: Icon(Icons.commute),
                label: 'Commute',
              ),
              NavigationDestination(
                selectedIcon: Icon(Icons.bookmark),
                icon: Icon(Icons.bookmark_border),
                label: 'Saved',
              ),
            ],
          ),
    

    follow official documentation https://api.flutter.dev/flutter/material/NavigationBar-class.html (material you/3)

    or If you are using other package for it check its documentation

    or you can also use https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html (material 2)