flutter实现底部导航栏
作者:伟雪无痕 发布时间:2023-08-23 01:06:13
标签:flutter,导航栏
本文实例为大家分享了flutter实现底部导航栏的具体代码,供大家参考,具体内容如下
一.flutter底部导航栏常用组件BottomNavigationBar 属性介绍
BottomNavigationBar({
Key? key,
required this.items, //必填项,设置各个按钮
this.onTap, //点击事件
this.currentIndex = 0, //当前选中item下标
this.elevation, //控制阴影高度
this.type, //BottomNavigationBarType,默认 fixed,设置为 shifting 时,需要设置选中样式,和未选中样式,提供一个特殊动画
Color? fixedColor, //选中 item 填充色
this.backgroundColor, //整个BottomNavigationBar 背景色
this.iconSize = 24.0, //图标大小
Color? selectedItemColor, //选中title填充色
this.unselectedItemColor, //未选中title填充色
this.selectedIconTheme, //选中item图标主题
this.unselectedIconTheme, //未选中item图标主题
this.selectedFontSize = 14.0, //选中title字体大小
this.unselectedFontSize = 12.0, //未选中title字体大小
this.selectedLabelStyle, //选中title样式 TextStyle
this.unselectedLabelStyle, //未选中title样式 TextStyle
this.showSelectedLabels, //是否展示选中title,默认为true
this.showUnselectedLabels, //是否展示未选中title,默认为true
this.mouseCursor, //鼠标悬停
this.enableFeedback,
this.landscapeLayout,
})
二.BottomNavigationBar的具体实现
1.创建四个页面,分别为,首页,通讯录,发现和我的,这里以homepage.dart为例,其他页面只需要修改对应内容显示即可,eg:
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget{
const HomePage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState()=>_HomePageState();
}
class _HomePageState extends State<HomePage>{
@override
Widget build(BuildContext context) {
return const Center(
child: Text(
"主页",
style:TextStyle(
color: Colors.black,
fontSize: 20
),
),
);
}
}
2.添加BottomNavigationBar,需要在主页中实现BottomNavigationBar,eg:
import 'package:flutter/material.dart';
import 'findpage.dart';
import 'mypage.dart';
import 'contactpage.dart';
import 'homepage.dart';
class MainPage extends StatefulWidget{
const MainPage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState()=>_MainPageState();
}
class _MainPageState extends State<MainPage>{
var allPages=[HomePage(),ContactPage(),FindPage(),MyPage()];
var currentIndex=0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"导航栏",
style: TextStyle(
color: Colors.black,
fontSize: 30,
),
textAlign: TextAlign.center,
),
),
body: allPages[currentIndex],
backgroundColor: Colors.green,
bottomNavigationBar: BottomNavigationBar(
currentIndex: currentIndex,
type: BottomNavigationBarType.fixed,
unselectedItemColor: Colors.grey,
selectedItemColor: Colors.blue,
/*unselectedLabelStyle:TextStyle(
color: Colors.black
),*/
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: "首页",
//backgroundColor:Colors.blue
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: "通讯录",
//backgroundColor:Colors.blue
),
BottomNavigationBarItem(
icon: Icon(Icons.find_in_page),
label: "发现",
//backgroundColor:Colors.blue
),
BottomNavigationBarItem(
icon: Icon(Icons.flip_outlined),
label: "我的",
//backgroundColor:Colors.blue
),
],
onTap: (index){
setState(() {
print("the index is :$index");
currentIndex=index;
});
},
),
);
}
}
三.实际效果展示,eg:
来源:https://blog.csdn.net/j086924/article/details/122347292


猜你喜欢
- 简介简单工厂模式 (Simple Factory) 又叫静态工厂方法(Static Factory Method)模式。简单工厂模式通常是定
- 一、参数校验springboot 使用校验框架validation校验方法的入参SpringBoot的Web组件内部集成了hibernate
- 前言背景平时开发中遇到根据当前用户的角色,只能查看数据权限范围的数据需求。列表实现方案有两种,一是在开发初期就做好判断赛选,但如果这个需求是
- 背景数据库在保存数据时,对于某些敏感数据需要脱敏或者加密处理,如果一个一个的去加显然工作量大而且容易出错,这个时候可以考虑使用 * ,本文针
- 删除本地仓库未下载完成的缓存文件(删除像图片显示这样以.lastUpdated结尾的文件)执行mvn -v确保maven命令可以正常执行执行
- 队列简介队列是一个有序列表,可以用数组或是链表来实现。遵循先入先出的原则。即先存入队列的数据,先取出,后存入的后取出。示意图:(使用数组模拟
- (注意:本文基于JDK1.8) 前言Vector是线程安全的动态数组类,提供4个创建Vector对象的构造方法,接下来我们逐个分析
- 本文实例为大家分享了ManualResetEvent的使用方法,供大家参考,具体内容如下1. 源码下载:下载地址:ManualResetEv
- C# 中的每个类或结构都隐式继承 Object 类。因此,C# 中的每个对象都会获得 ToString 方法,此方法返回该对象的字符串表示形
- 一、隐藏标题栏 //隐藏标题栏 &
- 集成使用1、添加 gradle 依赖implementation "com.ctrip.framework.apollo:apol
- 前言飞行棋小游戏是学习C#以来,接触的第一个游戏项目,根据小杨老师的思路引导,自己的代码也实现了功能,经过思路的梳理,试着不借助代码自己去实
- 本文实例讲述了Android 开发使用PopupWindow实现弹出警告框的复用类。分享给大家供大家参考,具体如下:Android开发中相信
- 项目中遇到springBoot+docker需要配置不同环境变量的问题,做个简单的总结:1.开发环境ide中启动项目可以通过ide的环境变量
- 1. 出故障了没办法,干it这一行,就得天天面对故障,大家就是传说中的消防员,到处救火。不过,这次的故障范围有点大,宿主机都打不开了。好在监
- 如果你是一名Web开发人员,那么用膝盖想也知道你的职业生涯大部分将使用Java而度过。这是一款商业级的编程语言,我们没有办法不接触它。对于J
- 大家最近都在讨论新鲜技术-flutter,小编也在学习中,遇到大家都遇到的问题,底部导航。下面给大家贴出底部导航的编写,主要参考了lime这
- 在上一篇文章中完成了 《Maven镜像地址大全 》,后来又花了时间又去收集并整理了关于 maven 远程仓库地址,并整理于此,关于 Mave
- 配置文件概述:应用程序配置文件是标准的 XML 文件,XML 标记和属性是区分大小写的。它是可以按需要更改的,开发人员可以使用配置文件来更改
- 本文实例为大家分享了java实现文件夹解压和压缩的具体代码,供大家参考,具体内容如下效果实现多个文件以及文件夹的压缩和解压代码分析impor