Flutter 的 BottomNavigationBar widget 需搭配 Scaffold 使用,可用以設定 Scaffold 下方的巡覽列。  

其建構子如下:

BottomNavigationBar({Key key, @required List items, ValueChanged onTap, int currentIndex: 0, BottomNavigationBarType type, Color fixedColor, double iconSize: 24.0 })

屬性如下:

NameTypeDescription
currentIndexintThe index into items of the current active item.
fixedColorColorThe color of the selected item when bottom navigation bar is BottomNavigationBarType.fixed.
iconSizedoubleThe size of all of the BottomNavigationBarItem icons.
itemsListThe interactive items laid out within the bottom navigation bar.
onTapValueChangedThe callback that is called when a item is tapped.
typeBottomNavigationBarTypeDefines the layout and behavior of a BottomNavigationBar.
hashCodeintThe hash code for this object.
keyKeyControls how one widget replaces another widget in the tree.
runtimeTypeTypeA representation of the runtime type of the object.

方法如下:

NameReturn TypeDescription
createState()_BottomNavigationBarStateCreates the mutable state for this widget at a given location in the tree.
createElement()StatefulElementCreates a StatefulElement to manage this widget’s location in the tree.
debugDescribeChildren()ListReturns a list of DiagnosticsNode objects describing this node’s children.
debugFillProperties(DiagnosticPropertiesBuilder properties)voidAdd additional properties associated with the node.
noSuchMethod(Invocation invocation)dynamicInvoked when a non-existent method or property is accessed.
toDiagnosticsNode({String name, DiagnosticsTreeStyle style })DiagnosticsNodeReturns a debug representation of the object that is used by debugging tools and by toStringDeep.
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug })StringReturns a string representation of this object.
toStringDeep({String prefixLineOne: ‘’, String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug })StringReturns a string representation of this node and its descendants.
toStringShallow({String joiner: ‘, ‘, DiagnosticLevel minLevel: DiagnosticLevel.debug })StringReturns a one-line detailed description of the object.
toStringShort()StringA short, textual description of this widget.

比較重要的屬性有 fixedColor,可設定選取項目的顏色,iconSize 屬性可設定項目圖示的大小,currentIndex 屬性可設定作用中的項目,items 屬性可設定可使用的項目。

使用時只要建立出 BottomNavigationBar 實體,並指給 Scoffold 的 bottomNabigationBar 屬性即可。

import 'package:flutter/material.dart';

void main() {
runApp(new MaterialApp(
home: new Scaffold(
bottomNavigationBar: new BottomNavigationBar(
fixedColor: Colors.blue,
iconSize: 64.0,
currentIndex: 1,
items: [
new BottomNavigationBarItem(
icon: new Icon(Icons.arrow_left),
title: new Text("Left"),
),
new BottomNavigationBarItem(
icon: new Icon(Icons.arrow_right),
title: new Text("Right"),
),
],
))));
}

1.png

2.png