I'm new in flutter. I create my first app with BottomNavigationBar and i would like use it for navigate in the pages.
But which is the best method for navigate?
This is my widget.
BottomNavigationBar buildBottomNavigationBar() {
return BottomNavigationBar(
showSelectedLabels: true,
showUnselectedLabels: false,
currentIndex: _selectedIndex,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.addchart_outlined), label: "Dati contagi"),
BottomNavigationBarItem(icon: Icon(Icons.coronavirus), label: "Home"),
BottomNavigationBarItem(
icon: Icon(Icons.help),
label: "Info",
),
],
selectedItemColor: Colors.blue,
onTap: _onItemTapped,
);
}
this is _onItemTapped:
void _onItemTapped(int index) {
setState(() {
if (_selectedIndex != index) {
_selectedIndex = index;
Navigator.pushNamed(context, SVConst.allRoute[_selectedIndex]);
}
});
}
this is SVConst.allRoute:
static const List<String> allRoute = <String>[
InfoViewRoute,
HomeViewRoute,
SettingsViewRoute,
];
But it no works perfectly.
You have suggest for me?