1.去除右上角debug标符
debugShowCheckedModeBanner: false,
2.手机屏幕的宽高
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
3.获取状态栏高度
MediaQuery.of(context).padding.top
4.计时器引入Timer它是在import ‘dart:async’;里每1秒执行一次
// 定义定时器
_timer = Timer.periodic(Duration(milliseconds: 1000), (timer) {
setState(() {
_currentTime--;
});
if (_currentTime <= 0) {
_jumpRootPage();
}
});
5.销毁页面重定向到首页
//销毁页面重定向到首页
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (BuildContext context) => RootPage()),
(route) => false);
6.底部导航栏
bottomNavigationBar: BottomNavigationBar(
items: _bottomNavBarList,
currentIndex: _currentIndex,
onTap: _onTabClick,
//底部tabbar导航栏文字出现
type: BottomNavigationBarType.fixed,
),
7.tabbar将button放在中间要注意的是bottomNavigationBar和floatingActionButton是同级
Scaffold(
body: Center(
child: Text('roott'),
),
bottomNavigationBar: BottomNavigationBar(
items: _bottomNavBarList,
currentIndex: _currentIndex,
onTap: _onTabClick,
//底部tabbar导航栏文字出现
type: BottomNavigationBarType.fixed,
),
floatingActionButton: _createMediaButton(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
);
8.模版序列化
- 在plugs里面安装Json2json_serializable
打开插件:
- macOS:Command + option + N
- Windows:Control + alt + N - 在yaml里面引入这三个环境
dependencies:
json_annotation: ^4.5.0
dev_dependencies:
build_runner: ^2.1.7
json_serializable: ^6.1.3
3.然后去新建一个model文件
4.然后在终端输入命令
flutter packages pub run build_runner build