Flutter基础总结(1)状态栏切换和底部按的突出
2020-03-12 本文已影响0人
总会颠沛流离
新型冠状病毒成了2020年飞出来的一只黑天鹅。这只黑天鹅的出现,让多少企业、多少人乱了阵脚。但是,一切偶然的背后都是必然。
病毒让本来祥和快乐的新年压抑了很多,让2020年的开春蒙上了一层迷雾,但大家不要忘了,生活和工作还是要继续,特别是在武汉地区的朋友,我们一定要相信,任何困难都难不倒伟大的中国人,这是一种名族自信,众志成城,终将克服,迎来曙光。
1:效果图
image.pngimage.png
2:废话就不读多说了 直接上代码
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(MyApp());
if (Platform.isAndroid) {
var systemUiOverlayStyle =
SystemUiOverlayStyle(statusBarColor: Colors.transparent);
/**
* 设置系统用户界面叠加样式
*/
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
}
class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return HomePageState();
}
}
/**
* 主页面
*/
class HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
List<String> _abs = ['A', 'B', 'C'];
//Tab
TabController _tabController;
//页面
PageController _pageController;
@override
void initState() {
// TODO: implement initState
super.initState();
_tabController = TabController(length: _abs.length, vsync: this);
_pageController = PageController(initialPage: 0);
_tabController.addListener(() {
if (_tabController.indexIsChanging) {
_pageController.animateToPage(_tabController.index,
duration: Duration(milliseconds: 300), curve: Curves.decelerate);
}
});
}
@override
void dispose() {
// TODO: implement dispose
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text("Deme"),
centerTitle: true,
automaticallyImplyLeading: true,
actions: <Widget>[
PopupMenuButton(
onSelected: (val) {
var position = -1;
switch (val) {
case 'A':
position = 0;
break;
case 'B':
position = 1;
break;
case 'C':
position = 2;
break;
}
_tabController.index = position;
},
icon: Icon(Icons.more_vert),
itemBuilder: (context) => List.generate(
_abs.length,
(index) => PopupMenuItem(
value: _abs[index],
child: Text(_abs[index]),
)),
)
],
bottom: TabBar(
labelColor: Colors.red,
unselectedLabelColor: Colors.white,
controller: _tabController,
isScrollable: false,
indicatorColor: Colors.yellow,
indicatorSize: TabBarIndicatorSize.tab,
indicatorWeight: 5.0,
tabs: List.generate(
_abs.length,
(index) => Tab(
text: _abs[index],
icon: Icon(Icons.android),
))),
),
drawer: Drawer(
child: SafeArea(
child: Container(
child: Text(
'Drawer',
style: TextStyle(
color: Theme.of(context).primaryColor, fontSize: 30.0),
),
),
),
),
body: PageView(
controller: _pageController,
/* children: _abs
.map((str) => TabChangePage(
content: str,
))
.toList(),*/
children: _abs.map((str) {
TabChangePage(
content: str,
);
}).toList(),
onPageChanged: (position) {
_tabController.index = position;
},
),
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
IconButton(
icon: Icon(
Icons.android,
size: 30.0,
color: Theme.of(context).primaryColor,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.phone_iphone,
size: 30.0,
color: Theme.of(context).primaryColor,
),
onPressed: () {},
)
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => print('Add'),
child: Icon(
Icons.add,
color: Colors.white,
),
tooltip: "varenyzc",
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
);
}
}
class TabChangePage extends StatelessWidget {
final String content;
TabChangePage({Key key, this.content}) : super(key: key);
@override
Widget build(BuildContext context) {
// TODO: implement build
return SafeArea(
child: Container(
alignment: Alignment.center,
child: Text(
content,
style:
TextStyle(color: Theme.of(context).primaryColor, fontSize: 30.0),
),
),
);
;
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
title: "DemoOne",
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}