点击上方“
刘望舒”,马上关注,早上
8:42推送
技术进阶关注“刘望舒”就对了
作者: 刘望舒
http://liuwangshu.cn/flutter/primer/6-material-components-2.html
Flutter基础系列文章
移动开发的跨平台技术演进
是谁走漏了风声,我已经用flutter了
不会Dart,还搞什么Flutter?
开发Flutter应用前需要先掌握什么?
Flutter必知必会的Material组件
前言
在上一篇 Flutter必知必会的Material组件中,我介绍了Material组件的MaterialApp、Scaffold、AppBar,这篇文章接着介绍Material组件中的BottomNavigationBar、TabBar、Drawer。
1.BottomNavigationBar
BottomNavigationBar是底部的导航栏,用于在3到5个的少量视图中进行选择。一般情况下,导航栏的选项卡由文本标签、图标或两者结合的形式组成。
底部导航栏通常与javaScaffold结合使用,它会作为Scaffold.bottomNavigationBar参数。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyStatefulWidget(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();//1
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int _selectedIndex = 0;
static const List _widget = [
Text('Index 0:首页',
),
Text('Index 1: 通讯录',
),
Text('Index 2: 设置',
),
];@overrideWidget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('BottomNavigationBar示例'),
),
body: Center(
child: _widget.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('首页'),
),
BottomNavigationBarItem(
&nbs