20、Scaffold属性 BottomNavigationBar 自定义底部导航
BottomNavigationBar 常见的属性

BottomNavigationBar 底部菜单选中
class MyFlutter1 extends StatefulWidget {
const MyFlutter1({super.key});
@override
State<MyFlutter1> createState() => _MyFlutter1State();
}
class _MyFlutter1State extends State<MyFlutter1> {
int _currentIndex =0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("这是导航栏")),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex, //默认选中第几个
iconSize: 35,
type:BottomNavigationBarType.fixed, //如果底部有4个或者4个以上的进行选择
fixedColor: const Color.fromARGB(255, 54, 244, 171), //选中的颜色
onTap: (index){ //选中变化回调函数
print("监听$index");
setState(() {
_currentIndex = index;
});
},
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
BottomNavigationBarItem(icon: Icon(Icons.timeline), label: "时间"),
BottomNavigationBarItem(icon: Icon(Icons.my_library_add), label: "我的"),
]),
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [],
)),
);
}
}
BottomNavigationBar 底部菜单选中 换页面内容
class MyFlutter1 extends StatefulWidget {
const MyFlutter1({super.key});
@override
State<MyFlutter1> createState() => _MyFlutter1State();
}
class _MyFlutter1State extends State<MyFlutter1> {
int _currentIndex =0;
final List<Widget> _pages = [
const HomePage(),
const TimePag(),
const myHome()
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("这是导航栏")),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex, //默认选中第几个
fixedColor: const Color.fromARGB(255, 54, 244, 171), //选中的颜色
unselectedItemColor: Colors.grey, // 设置未选中按钮的颜色为灰色
onTap: (index){ //选中变化回调函数 print("监听$index"); setState(() { _currentIndex = index; }); },
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
BottomNavigationBarItem(icon: Icon(Icons.timeline), label: "时间"),
BottomNavigationBarItem(icon: Icon(Icons.my_library_add), label: "我的"),
]),
body: _pages[_currentIndex],
);
}
}
20、Scaffold属性 BottomNavigationBar 自定义底部导航的更多相关文章
- 15 Flutter BottomNavigationBar自定义底部导航条 以及实现页面切换 以及模块化
效果: /** * Flutter BottomNavigationBar 自定义底部导航条.以及实现页面切换: * BottomNavigationBar是底部导航条,可以让我们定义底部Tab ...
- BottomNavigationBar 自定义 底部导航条
在flutter中,BottomNavigationBar 是底部导航条,可以让我们定义底部 Tab 切换,bottomNavigationBar是 Scaffold 组件的参数. BottomNav ...
- tab 切换 和 BottomNavigationBar 自定义 底部导航条
BottomNavigationBar 组件 BottomNavigationBar 是底部导航条,可以让我们定义底部 Tab 切换,bottomNavigationBar是 Scaffold ...
- BottomNavigationBar 自定义 底部导航条、以及实现页面切换
一.Flutter BottomNavigationBar 组件 BottomNavigationBar 是底部导航条,可以让我们定义底部 Tab 切换,bottomNavigationBar是 Sc ...
- 【Flutter】容器类组件之Scaffold、TabBar、底部导航
前言 一个完整的路由页可能会包含导航栏.抽屉菜单(Drawer)以及底部Tab导航菜单等.Flutter Material组件库提供了一些现成的组件来减少开发任务.Scaffold是一个路由页的骨架, ...
- 微信小程序-自定义底部导航
代码地址如下:http://www.demodashi.com/demo/14258.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...
- 微信小程序自定义底部导航栏组件+跳转
微信小程序本来封装有底部导航栏,但对于想自定义样式和方法的开发者来说,这并不是很好. 参考链接:https://github.com/ljybill/miniprogram-utils/tree/ma ...
- uniapp 小程序实现自定义底部导航栏(tarbar)
在小程序开发中,默认底部导航栏很难满足实际需求,好在官方给出了自定义形式,效果如下: 话不多说,直接上代码 1.组件 custom-tarbar.vue文件 <template> < ...
- 自定义底部导航栏(tabBar)
前言如果大家用过微信提供的tabBar就会发现,他的tabBar有很大的局限性.暂且不说样式局限性了,他提供的app.json配置文件中没有function.这也就意味着使用它提供的这个组件,你只能用 ...
- 小程序 mpvue自定义底部导航栏
1.在compontents新建文件放入 <template> <section class="tabBar-wrap"> <article clas ...
随机推荐
- MySQL系列之——MySQL介绍和安装、MySQL简介及产品线、安装方式(源码安装 rpm方式 yum方式 通用二进制安装)
文章目录 一 MySQL介绍和安装 1.1 什么是数据? 1.2 什么是数据库管理系统(DBMS)? 1.3 数据库管理系统种类 二 MySQL简介及产品线 2.1 MySQL行业主流版本 2.2 企 ...
- snowboy 无法 install
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple snowboy Looking in indexes: https://pypi.tun ...
- Blackmail
Blackmail Arthur Hailey The chief house officer, Ogilvie, who had declared he would appear at the Cr ...
- studio
- 研发三维GIS系统笔记/框架改造/智能指针重构框架-003
1. 使用智能指针重构系统 原有的系统都是裸指针,在跨模块与多线程中使用裸指针管理起来很麻烦,尤其是多任务系统中会出现野指针 1 class CELLTileTask :public CELLTask ...
- Kubernetes集群管理面板的安装及使用
Kubernetes集群管理面板的安装及使用 1.前言 若海的腾讯云Lighthouse组建跨地域Kubernetes集群,让我成功体验到了Kubernetes集群诸多优点,但是非技术出生的我,长时间 ...
- C语言存储类别
对于C语言中的变量,存储类别可分为4种:auto(自动存储).static(静态存储).register(寄存器存储).extern(外部存储). auto自动存储 函数中的局部变量,如果不专门声明为 ...
- 21. 从零用Rust编写正反向代理,tokio竟然这样对待socket!
wmproxy wmproxy已用Rust实现http/https代理, socks5代理, 反向代理, 静态文件服务器,四层TCP/UDP转发,内网穿透,后续将实现websocket代理等,会将实现 ...
- [Python急救站]密码判断
用Python做一个密码判断,用户输入注册密码,需要6位以上,包含数字.大写字母.小写字母. import re a = re.compile('[a-z]') b = re.compile('[A- ...
- python 执行脚本,并将输出打印到文件
转载请注明出处: 在使用 python 直接执行脚本时,执行的相关输出会打印到当前的控制台,如果想输出到指定的文件,可以采用以下几种方式: 1.在启动时,使用 > 操作符,该操作符会将输出写入到 ...