内容简介:BottomNavigationBarBottomNavigationBar 是属于 Scaffold 中的一个位于底部的控件。通常和 BottomNavigationBarItem 配合使用。
BottomNavigationBar
BottomNavigationBar 是属于 Scaffold 中的一个位于底部的控件。通常和 BottomNavigationBarItem 配合使用。
BottomNavigationBar构造方法:
BottomNavigationBar({
Key key,
@required this.items,
this.onTap,
this.currentIndex = 0,
this.elevation = 8.0,
BottomNavigationBarType type,
Color fixedColor,
this.backgroundColor,
this.iconSize = 24.0,
Color selectedItemColor,
this.unselectedItemColor,
this.selectedIconTheme = const IconThemeData(),
this.unselectedIconTheme = const IconThemeData(),
this.selectedFontSize = 14.0,
this.unselectedFontSize = 12.0,
this.selectedLabelStyle,
this.unselectedLabelStyle,
this.showSelectedLabels = true,
bool showUnselectedLabels,
})
BottomNavigationBarItem
底部导航栏要显示的Item,有图标和标题组成
BottomNavigationBarItem构造方法:
const BottomNavigationBarItem({
@required this.icon,
this.title,
Widget activeIcon,
this.backgroundColor,
})
构建BottomNavigationBar
// 创建底部BottomNavigationBar
BottomNavigationBar _bottomNavigationBar(List <String>titles, List <String>icons){
return BottomNavigationBar(
items: [
_bottomBarItem(titles[0], icons[0]),
_bottomBarItem(titles[1], icons[1]),
_bottomBarItem(titles[2], icons[2]),
_bottomBarItem(titles[3], icons[3]),
],
currentIndex: _currentIndex,
type: BottomNavigationBarType.fixed,// 当items大于3时需要设置此类型
onTap: _bottomBarItemClick,
selectedFontSize: 12,
);
}
// 创建item
BottomNavigationBarItem _bottomBarItem(String title, String iconName,) {
return BottomNavigationBarItem(
icon: _image(iconName),
title: Text(title),
activeIcon: _image('${iconName}_select'),
backgroundColor: Colors.white,
);
}
//image
Widget _image(String iconName) {
return Image.asset(
'assets/images/${iconName}@2x.png',// 在项目中添加图片文件夹
width: 24,
height: 24,
);
}
//item点击事件
_bottomBarItemClick(int index) {
setState(() {
_currentIndex = index;
});
}
调用构建方法
// 当前选中的索引
int _currentIndex = 0;
//item点击事件
_bottomBarItemClick(int index) {
setState(() {
_currentIndex = index;
});
}
// 数据
List titles = <String>['首页', '收藏', '消息', '我的'];
List icons = <String>['tabbar_discover', 'tabbar_favorite', 'tabbar_message', 'tabbar_me'];
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: _bottomNavigationBar(titles, icons),
);
}
样式显示 :
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 封装JDBC—非框架开发必备的封装类
- SpringBlade 2.3.2 发布,增加 OSS 封装及单元测试封装
- SpringBlade 2.3.2 发布,增加 OSS 封装及单元测试封装
- docker 封装 alinode
- 封装Apk签名工具
- axios封装笔记
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
计算统计
Geof H.Givens、Jennifer A.Hoeting / 王兆军、刘民千、邹长亮、杨建峰 / 人民邮电出版社 / 2009-09-01 / 59.00元
随着计算机的快速发展, 数理统计中许多涉及大计算量的有效方法也得到了广泛应用与迅猛发展, 可以说, 计算统计已是统计中一个很重要的研究方向. 本书既包含一些经典的统计计算方法, 如求解非线性方程组的牛顿方法、传统的随机模拟方法等, 又全面地介绍了近些年来发展起来的某些新方法, 如模拟退火算法、基因算法、EM算法、MCMC方法、Bootstrap方法等, 并通过某些实例, 对这些方法的应用进行......一起来看看 《计算统计》 这本书的介绍吧!