BottomNavigationBar is a widget in Flutter that lets users switch between different views or screens using a bar at the bottom of the app. It’s a key navigation pattern in many mobile apps, especially for organizing major features like Home, Search, and Profile.
Source Code
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State {
int _currentIndex = 0;
final List _pages = [
Center(child: Text('Home Page')),
Center(child: Text('Search Page')),
Center(child: Text('Profile Page')),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Bottom Tab Nav')),
body: _pages[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (int index) {
setState(() {
_currentIndex = index;
});
},
selectedItemColor: Colors.teal,
unselectedItemColor: Colors.grey,
backgroundColor: Colors.white,
type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
tooltip: 'Go to Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
tooltip: 'Find something',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
tooltip: 'View your profile',
),
],
),
);
}
}
Ai Code Analizer
🎨 3. Important Properties Used
| Property | Description |
|---|---|
currentIndex | Indicates which tab is currently active. |
onTap | Callback that updates the active tab on tap. |
items | List of BottomNavigationBarItems representing each tab. |
selectedItemColor | Color of the selected tab. |
unselectedItemColor | Color of the tabs not currently selected. |
backgroundColor | Background color of the navigation bar. |
type | Layout behavior — use fixed for >3 tabs or shifting for animations. |
tooltip | Optional label shown on long press (improves accessibility). |
