【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目录下,我们新建下面四 ...
随机推荐
- 阿里云李刚:下一代低延时的直播CDN
在上周落幕帷幕的多媒体领域技术盛会——LiveVideoStackCon音视频技术大会上,阿里云的高级技术专家李刚进行了<下一代低延时的直播CDN>技术分享.主讲人李刚,多年关注在CDN这 ...
- php max()函数 语法
php max()函数 语法 作用:从所有参数中找到最大数 语法:max(X,Y,Z) 或者max(array(X,Y,Z)) 参数:max函数中参数至少一个,可以多个参数,也可以是数组. 说明:如果 ...
- [HDU2276]Kiki & Little Kiki 2
题目:Kiki & Little Kiki 2 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2276 分析: 1)如果前一盏灯亮着,则改变这一盏灯 ...
- ip地址与子网掩码----基础知识
前言 IP地址有三种基本类型,由网络号的第一组数字来表示. A类地址的第一组数字为1-126. B类地址的第一组数字为128-191. C类地址的第一组数字为192-223. 注:数字0和 127不作 ...
- python的迭代器(转自廖雪峰老师python基础)
我们已经知道,可以直接作用于for循环的数据类型有以下几种:一类是集合数据类型,如list.tuple.dict.set.str等:一类是generator,包括生成器和带yield的generato ...
- 老牌激活工具 — Microsoft Toolkit 2.5.1正式版【转】
老牌激活工具 — Microsoft Toolkit 2.5.1正式版 Microsoft Toolkit 2.5.1是一个一键激活MS Office 及 win系统的工具.原理就是利用KMS来激活 ...
- 建站手册-网站建设:Web 安全
ylbtech-建站手册-网站建设:Web 安全 1.返回顶部 1. http://www.w3school.com.cn/site/site_security.asp 2. 2.返回顶部 1. 此刻 ...
- spring4.1.8扩展实战之三:广播与监听
提到广播与监听,我们常常会想到RabbitMQ.Kafka等消息中间件,这些常用于分布式系统中多个应用之间,有时候应用自身内部也有广播和监听的需求(例如某个核心数据发生变化后,有些业务模块希望立即被感 ...
- sublime中使用插件anaconda而在代码中出现方框
这个标志是说不符合PEP8标准,比如使用了Tab做缩进:一行过长等问题. 可以在可以在 Sublime > Preferences > Package Settings > Anac ...
- go递归遍历文件目录
package main import ( "fmt" "io/ioutil" "log" ) //文件目录树形结构节点 type dirT ...