Flutter布局-BottomNavigationBar组件
BottomNavigationBar是底部导航条,可以让我们定义底部tab切换,BottomNavigationBar是Scaffold组件的参数。
BottomNavigationBar组件的常用属性
| 属性名 |
说明 |
| items |
List<BottomNavigationBar> 底部导航按钮集合 |
| iconSize |
icon |
| currentIndex |
默认选中第几个 |
| onTap |
选中变换回调函数 |
| fixedColor |
选中的颜色 |
| type |
BottomNavigationBarType.fixed (当底部导航栏items>3的时候必须设置此属性) |
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
| import 'package:flutter/material.dart'; import './data/listData.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text("有状态组件"), ), body: HomePage(), ), ); } }
class HomePage extends StatefulWidget { HomePage({Key key}) : super(key: key);
@override _HomePageState createState() => _HomePageState(); }
class _HomePageState extends State<HomePage> { int countNum = 0; @override Widget build(BuildContext context) { return Column( children: <Widget>[ SizedBox( height: 200.0, ), Text("nihao${this.countNum}"), SizedBox( height: 20.0, ), RaisedButton( onPressed: () { setState(() { this.countNum++; }); print(this.countNum); }, child: Text("buttom"), ), ], ); } }
|