diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index 5840c0efdcefb2..5513c0c24d7889 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -68,6 +68,61 @@ enum BottomNavigationBarType { /// case it's assumed that each item will have a different background color /// and that background color will contrast well with white. /// +/// ## Sample Code +/// +/// This example shows a [BottomNavigationBar] as it is used within a [Scaffold] +/// widget. The [BottomNavigationBar] has three [BottomNavigationBarItem] +/// widgets and the [currentIndex] is set to index 1. The color of the selected +/// item is set to a purple color. A function is called whenever any item is +/// tapped and the function helps display the appropriate [Text] in the body of +/// the [Scaffold]. +/// +/// ```dart +/// class MyHomePage extends StatefulWidget { +/// MyHomePage({Key key}) : super(key: key); +/// +/// @override +/// _MyHomePageState createState() => _MyHomePageState(); +/// } +/// +/// class _MyHomePageState extends State { +/// int _selectedIndex = 1; +/// final _widgetOptions = [ +/// Text('Index 0: Home'), +/// Text('Index 1: Business'), +/// Text('Index 2: School'), +/// ]; +/// +/// @override +/// Widget build(BuildContext context) { +/// return Scaffold( +/// appBar: AppBar( +/// title: Text('BottomNavigationBar Sample'), +/// ), +/// body: Center( +/// child: _widgetOptions.elementAt(_selectedIndex), +/// ), +/// bottomNavigationBar: BottomNavigationBar( +/// items: [ +/// BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')), +/// BottomNavigationBarItem(icon: Icon(Icons.business), title: Text('Business')), +/// BottomNavigationBarItem(icon: Icon(Icons.school), title: Text('School')), +/// ], +/// currentIndex: _selectedIndex, +/// fixedColor: Colors.deepPurple, +/// onTap: _onItemTapped, +/// ), +/// ); +/// } +/// +/// void _onItemTapped(int index) { +/// setState(() { +/// _selectedIndex = index; +/// }); +/// } +/// } +/// ``` +/// /// See also: /// /// * [BottomNavigationBarItem]