【Flutter学习】基本组件之BottomNavigationBar底部导航栏
一,概述
BottomNavigationBar即是底部导航栏控件,显示在页面底部的设计控件,用于在试图切换,底部导航栏包含多个标签、图标或者两者搭配的形式,简而言之提供了顶级视图之间的快速导航。
二,Bar关键元素
- BottomNavigationBar
- BottomNavigationBar 是属于 Scaffold 中的一个位于底部的控件。通常和 BottomNavigationBarItem 配合使用。
- BottomNavigationBar构造方法
BottomNavigationBar({
Key key,
@required this.items,
this.onTap,
this.currentIndex = ,
BottomNavigationBarType type,
this.fixedColor,
this.iconSize = 24.0,
}) - BottomNavigationBar 参数含义

- BottomNavigationBar 是属于 Scaffold 中的一个位于底部的控件。通常和 BottomNavigationBarItem 配合使用。
- BottomNavigationBarItem
- 底部导航栏要显示的Item,有图标和标题组成
- BottomNavigationBarItem构造方法
const BottomNavigationBarItem({
@required this.icon,
this.title,
Widget activeIcon,
this.backgroundColor,
}) - BottomNavigationBarItem 参数含义

三,实现过程
- 1.构建底部标签
// 导航图标
final List<BottomNavigationBarItem> bottomNavItems = [
new BottomNavigationBarItem(
backgroundColor: Colors.blue,
icon: Icon(Icons.home),
title: new Text("首页")
), new BottomNavigationBarItem(
backgroundColor: Colors.green,
icon: Icon(Icons.message),
title: new Text('消息')
), new BottomNavigationBarItem(
backgroundColor: Colors.amber,
icon: Icon(Icons.shopping_cart),
title: new Text("购物车")
), new BottomNavigationBarItem(
backgroundColor: Colors.red,
icon: Icon(Icons.person),
title: Text('个人中心')
)
]; - 2.构建导航显示的页面
//视图view
final pageViews = [
new HomePage(),
new MsgPage(),
new CartPage(),
new PersonPage()
]; - 2.创建底部导航栏
/** 如果点击的导航页不是当前项,切换*/
void _changePage(int index) {
if(index != currentIndex){
setState(() {
currentIndex = index;
});
}
} @override
Widget build(BuildContext context) {
// TODO: implement build
return new DefaultTabController(
length: myTabs.length,
child: new Scaffold(
appBar: new AppBar(
title: new Text('顶部标签栏'),
bottom: new TabBar(
indicatorColor: Colors.blue,
tabs: myTabs,
isScrollable: true,
),
), bottomNavigationBar: new BottomNavigationBar(
items: bottomNavItems,
currentIndex: currentIndex,
type: BottomNavigationBarType.fixed,
onTap: (index) {
_changePage(index);
},
),
body: pageViews[currentIndex],
),
);
} - 3.完成
import 'package:flutter/material.dart';
import './HomePage.dart';
import './CartPage.dart';
import './MsgPage.dart';
import './PersonPage.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return new MaterialApp(
title: '页面布局',
theme:new ThemeData(
primarySwatch: Colors.red
),
home: new App(),
);
}
} class App extends StatefulWidget { @override
State<StatefulWidget> createState() {
// TODO: implement createState
return new AppState();
}
} class AppState extends State<App> { // 导航图标
final List<BottomNavigationBarItem> bottomNavItems = [
new BottomNavigationBarItem(
backgroundColor: Colors.blue,
icon: Icon(Icons.home),
title: new Text("首页")
), new BottomNavigationBarItem(
backgroundColor: Colors.green,
icon: Icon(Icons.message),
title: new Text('消息')
), new BottomNavigationBarItem(
backgroundColor: Colors.amber,
icon: Icon(Icons.shopping_cart),
title: new Text("购物车")
), new BottomNavigationBarItem(
backgroundColor: Colors.red,
icon: Icon(Icons.person),
title: Text('个人中心')
)
]; int currentIndex; //视图view
final pageViews = [
new HomePage(),
new MsgPage(),
new CartPage(),
new PersonPage()
]; @override
void initState() {
super.initState();
currentIndex = ;
} /** 如果点击的导航页不是当前项,切换*/
void _changePage(int index) {
if(index != currentIndex){
setState(() {
currentIndex = index;
});
}
} @override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
appBar: new AppBar(
title: new Text('顶部标签栏'),
), bottomNavigationBar: new BottomNavigationBar(
items: bottomNavItems,
currentIndex: currentIndex,
type: BottomNavigationBarType.fixed,
onTap: (index) {
_changePage(index);
},
),
body: pageViews[currentIndex],
);
}
}
【Flutter学习】基本组件之BottomNavigationBar底部导航栏的更多相关文章
- Android学习总结——输入法将BottomNavigationBar(底部导航栏)顶上去的问题
在应用清单中给当前<Activity>设置: android:windowSoftInputMode="adjustPan" 关于android:windowSoftI ...
- Flutter - BottomNavigationBar底部导航栏切换后,状态丢失
如果你用过BottomNavigationBar.TabBar.还有Drawer,你就会发现,在切换页面之后,原来的页面状态就会丢失. 要是上一页有一个数据列表,很多数据,你滚动到了下头,切换页面后, ...
- 01 uni-app框架学习:项目创建及底部导航栏tabBar配置
1.创建一个项目类型选择uniapp 2. pages里新建3个页面如下 3.在pages.json中配置底部导航tabBar 效果展示:
- Flutter - BottomNavigationBar底部导航栏切换后,状态丢失。底部
import 'package:flutter/material.dart'; import './pages/home_page.dart'; import './pages/book_page.d ...
- 20个Flutter实例视频教程-第02节: 底部导航栏制作-2
视频地址: https://www.bilibili.com/video/av39709290?p=2 博客地址: https://jspang.com/post/flutterDemo.html#t ...
- 底部导航栏使用BottomNavigationBar
1.github地址 https://github.com/zhouxu88/BottomNavigationBar 2.基本使用 2,1添加依赖 implementation 'com.ashokv ...
- Flutter——BottomNavigationBar组件(底部导航栏组件)
BottomNavigationBar常用的属性: 属性名 说明 items List<BottomNavigationBarItem> 底部导航条按钮集合 iconSize icon c ...
- Flutter 底部导航栏bottomNavigationBar
实现一个底部导航栏,包含3到4个功能标签,点击对应的导航标签可以切换到对应的页面内容,并且页面抬头显示的内容也会跟着改变. 实际上由于手机屏幕大小的限制,底部导航栏的功能标签一般在3到5个左右,如果太 ...
- Flutter移动电商实战 --(4)打通底部导航栏
关于界面切换以及底栏的实现可参考之前写的一篇文章:Flutter实 ViewPager.bottomNavigationBar界面切换 1.新建4个基本dart文件 在pages目录下,我们新建下面四 ...
随机推荐
- LDD3 第7章 Time,Delays and Deferred Work
处理时间委托包括如下任务,按复杂度依次上升: 测量时间流失和比较时间 知道当前时间 指定时间量的延时操作 调度异步函数在之后的时间发生 一.测量时间流失 系统定时硬件规律的产生定时器中断,在内核启动阶 ...
- BZOJ 2694: Lcm 莫比乌斯反演 + 积性函数 + 线性筛 + 卡常
求 $\sum_{i=1}^{n}\sum_{j=1}^{m}lcm(i,j)\mu(gcd(i,j))^2$ $\Rightarrow \sum_{d=1}^{n}\mu(d)^2\sum_{i ...
- 洛谷P3374(线段树)(询问区间和,支持单点修改)
洛谷P3374 //询问区间和,支持单点修改 #include <cstdio> using namespace std; ; struct treetype { int l,r,sum; ...
- vue开发微信公众号--地图
在最近开发的微信公众号中,要实现一个打卡功能: 由于个人感觉微信SDK里面的地图不太好用,所以使用了腾讯地图. 在项目中引入腾讯地图 1,需要登录腾讯地图网站,注册一个账户,获得一个key. 2,然后 ...
- 2019 牛客暑期多校 第三场 F Planting Trees (单调队列+尺取)
题目:https://ac.nowcoder.com/acm/contest/883/F 题意:求一个矩阵最大面积,这个矩阵的要求是矩阵内最小值与最大值差值<=m 思路:首先我们仔细观察范围,我 ...
- Django中的get()和filter()区别
前言 在django中,我们查询经常用的两个API中,会经常用到get()和filter()两个方法,两者的区别是什么呢? object.get()我们得到的是一个对象,如果在数据库中查不到这个对象或 ...
- python中常用得字符串,列表函数汇总
字符串函数: 1,replace函数,替换函数.s = s.replace(old,new),老得元素被新的元素替换.注意不能直接写s.replace(old,new).要写s=s.replace(o ...
- hdu 5517 Triple
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5517 ------------------------------------------------ ...
- 109、TensorFlow计算张量的值
# 当计算图创建成功时 # 你就可以运行这个计算图,然后生成一个新的张量 # 并且得到这个张量指向的计算图中具体的数值 #这个功能在debug的时候非常有必要 #最简单获得张量具体值的方法是使用Ten ...
- 牛客 在其他数都出现k次的数组中找到出现1次的数
题目链接:https://www.nowcoder.com/practice/26e46f1f5e0d48c4b9ba13fe3e8d0ec6?tpId=101&tqId=33216& ...