ref – https://api.flutter.dev/flutter/material/BottomNavigationBar-class.html
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | /// Flutter code sample for BottomNavigationBar // This example shows a [BottomNavigationBar] as it is used within a [Scaffold] // widget. The [BottomNavigationBar] has three [BottomNavigationBarItem] // widgets, which means it defaults to [BottomNavigationBarType.fixed], and // the [currentIndex] is set to index 0. The selected item is // amber. The `_onItemTapped` function changes the selected item's index // and displays a corresponding message in the center of the [Scaffold]. import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); /// This is the main application widget. class MyApp extends StatelessWidget {   const MyApp({Key? key}) : super(key: key);   static const String _title = 'Flutter Code Sample';   @override   Widget build(BuildContext context) {     return const MaterialApp(       title: _title,       home: MyStatefulWidget(),     );   } } /// This is the stateful widget that the main application instantiates. class MyStatefulWidget extends StatefulWidget {   const MyStatefulWidget({Key? key}) : super(key: key);   @override   _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); } /// This is the private State class that goes with MyStatefulWidget. class _MyStatefulWidgetState extends State<MyStatefulWidget> {   int _selectedIndex = 0;   static const TextStyle optionStyle =       TextStyle(fontSize: 30, fontWeight: FontWeight.bold);   static const List<Widget> _widgetOptions = <Widget>[     Text(       'Index 0: Home',       style: optionStyle,     ),     Text(       'Index 1: Business',       style: optionStyle,     ),     Text(       'Index 2: School',       style: optionStyle,     ),   ];   void _onItemTapped(int index) {     setState(() {       _selectedIndex = index;     });   }   @override   Widget build(BuildContext context) {     return Scaffold(       appBar: AppBar(         title: const Text('BottomNavigationBar Sample'),       ),       body: Center(         child: _widgetOptions.elementAt(_selectedIndex),       ),       bottomNavigationBar: BottomNavigationBar(         items: const <BottomNavigationBarItem>[           BottomNavigationBarItem(             icon: Icon(Icons.home),             label: 'Home',           ),           BottomNavigationBarItem(             icon: Icon(Icons.business),             label: 'Business',           ),           BottomNavigationBarItem(             icon: Icon(Icons.school),             label: 'School',           ),         ],         currentIndex: _selectedIndex,         selectedItemColor: Colors.amber[800],         onTap: _onItemTapped,       ),     );   } } |