防采集标记:亢少军老师的课程和资料
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Cupertino导航组件集',
theme: ThemeData.light(), //浅色主题
home: MyPage(),
);
}
}
class MyPage extends StatefulWidget {
@override
_MyPageState createState() => _MyPageState();
}
class _MyPageState extends State {
@override
Widget build(BuildContext context) {
//最外层导航选项卡
return CupertinoTabScaffold(
//底部选项卡
tabBar: CupertinoTabBar(
backgroundColor: CupertinoColors.lightBackgroundGray, //选项卡背景色
items: [
//选项卡项 包含图标及文字
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.home),
title: Text('主页'),
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.conversation_bubble),
title: Text('聊天'),
),
],
),
tabBuilder: (context, index) {
//选项卡绑定的视图
return CupertinoTabView(
builder: (context) {
switch (index) {
case 0:
return HomePage();
break;
case 1:
return ChatPage();
break;
default:
return Container();
}
},
);
},
);
}
}
//主页
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
//基本布局结构,包含内容和导航栏
navigationBar: CupertinoNavigationBar(
//导航栏 只包含中部标题部分
middle: Text("主页"),
),
child: Center(
child: Text(
'主页',
style: Theme.of(context).textTheme.button,
),
),
);
}
}
//聊天页面
class ChatPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
//导航栏 包含左中右三部分
middle: Text("聊天面板"),//中间标题
trailing: Icon(CupertinoIcons.add),//右侧按钮
leading: Icon(CupertinoIcons.back),//左侧按钮
),
child: Center(
child: Text(
'聊天面板',
style: Theme.of(context).textTheme.button,
),
),
);
}
}
- Flutter技术入门与实战: http://product.dangdang.com/26485813.html
- Flutter交流学习群:894109159
- Flutter开源项目请关注: https://github.com/kangshaojun
- Flutter视频教程:https://edu.csdn.net/lecturer/2436
@作者: 亢少军