From a0010d391c04a488999ec11bc36654751f70be3e Mon Sep 17 00:00:00 2001 From: Philip Date: Wed, 17 Oct 2018 00:54:26 +0100 Subject: [PATCH] Added sample code for BottomNavigationBar widget [#21136] (#21615) * Added sample code for BottomNavigationBar widget [#21136] * bottomnavigationbaritems made single line --- .../src/material/bottom_navigation_bar.dart | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index 5840c0efdc..5513c0c24d 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]