Component - Bottom navigation bar
A Bottom Navigation Bar is a horizontal bar at the bottom of the screen that lets users switch between main sections of an app quickly. It usually shows icons and labels for each section.
A Bottom Navigation Bar is a horizontal bar at the bottom of the screen that lets users switch between main sections of an app quickly. It usually shows icons and labels for each section.
Scaffold
├── AppBar
├── body: Center
│ └── Text
└── bottomNavigationBar: BottomNavigationBar
├── BottomNavigationBarItem (Home)
├── BottomNavigationBarItem (Search)
└── BottomNavigationBarItem (Profile)BottomNavigationBar in a Flutter app?items property with a list of BottomNavigationBarItem widgets.items with BottomNavigationBarItem including icon and label._selectedIndex after tapping the second tab?int _selectedIndex = 0;
BottomNavigationBar(
currentIndex: _selectedIndex,
onTap: (int index) {
_selectedIndex = index;
},
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
BottomNavigationBarItem(icon: Icon(Icons.settings), label: 'Settings'),
],
)onTap callback receives the tapped tab's index and assigns it to _selectedIndex._selectedIndex becomes 1.int _selectedIndex = 0;
BottomNavigationBar(
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
BottomNavigationBarItem(icon: Icon(Icons.settings), label: 'Settings'),
],
onTap: (int index) {
_selectedIndex = index;
},
)currentIndex property is needed to tell the widget which tab is active.currentIndex, the UI won't update to show the selected tab visually.Pass the test and this pattern moves unknown