当前位置: 首页 > news >正文

flutter开发实战-设置bottomNavigationBar中间按钮悬浮效果

flutter开发实战-设置bottomNavigationBar中间按钮悬浮的效果

在使用tabbar时候,可以使用bottomNavigationBar来设置中间凸起的按钮,如下

一、效果图

中间按钮凸起的效果图如下

在这里插入图片描述

二、实现代码

我们使用BottomAppBar
一个容器,通常与[Sscaffold.bottomNavigationBar]一起使用。

使用的示例代码

Scaffold(bottomNavigationBar: BottomAppBar(color: Colors.white,child: bottomAppBarContents,),floatingActionButton: const FloatingActionButton(onPressed: null),)

设置中间的凸起按钮,可以设置BottomAppBar的shape为:CircularNotchedRectangle,中间悬浮按钮嵌入BottomAppBar
设置notchMargin缺口边距。
设置floatingActionButtonLocation:FloatingActionButtonLocation.centerDocked,//放在中间

完整代码如下

import 'package:flutter/material.dart';class TabDemoPage extends StatefulWidget {const TabDemoPage({super.key});@overrideState<TabDemoPage> createState() => _TabDemoPageState();
}class _TabDemoPageState extends State<TabDemoPage> {List<String> pageTitles = [];List<Widget> pageChildren = [];int currentIndex = 0;@overridevoid initState() {// TODO: implement initStatepageTitles = ["首页","我的"];pageChildren = [Container(color: Colors.lightBlueAccent,),Container(color: Colors.pinkAccent,)];super.initState();}@overridevoid dispose() {// TODO: implement disposesuper.dispose();}Widget build(BuildContext context) {return Scaffold(appBar: AppBar(title: Text(pageTitles[currentIndex]),///导航栏标题centerTitle: true,///导航栏标题居中显示(IOS默认居中,Android默认靠左)),body: pageChildren[currentIndex],bottomNavigationBar: BottomAppBar(shape: CircularNotchedRectangle(), ///中间悬浮按钮嵌入BottomAppBarnotchMargin: 10,///缺口边距child: Row(mainAxisAlignment: MainAxisAlignment.spaceAround,children: [IconButton(icon: Icon(Icons.home),onPressed: (){setState(() {currentIndex = 0;});}),IconButton(icon: Icon(Icons.person),onPressed: (){setState(() {currentIndex = 1;});}),],),),floatingActionButton: FloatingActionButton(foregroundColor: Colors.white,elevation: 10.0,///阴影onPressed: (){},child: Icon(Icons.add),),floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,//放在中间);}
}

三、小结

flutter开发实战-设置bottomNavigationBar中间按钮悬浮的效果

学习记录,每天不停进步。

http://www.lryc.cn/news/267120.html

相关文章:

  • 不同参数规模大语言模型在不同微调方法下所需要的显存总结
  • Crow:Middlewares 庖丁解牛6 middleware_call_helper
  • MyBatis:Generator
  • rabbitmq的事务实现、消费者的事务实现
  • 龙芯杯个人赛串口——做一个 UART串口——RS-232
  • 验证码服务使用指南
  • js中Math.min(...arr)和Math.max(...arr)的注意点
  • 【zookeeper特点和集群架构】
  • MySQL集群架构搭建以及多数据源管理实战
  • C# WPF上位机开发(从demo编写到项目开发)
  • 微信小程序引入 vant组件(详细步骤)
  • Django之按钮(actions)
  • 从YOLOv1到YOLOv8的YOLO系列最新综述【2023年4月】
  • 浙江大唐乌沙山电厂选择ZStack Cloud打造新一代云基础设施
  • 电脑开机快捷启动,启动菜单没有u盘怎么办
  • 线程的同步与互斥
  • 低代码实施复杂应用的实践方法
  • 算法学习系列(十一):KMP算法
  • ****Linux下Mysql的安装和配置
  • 第十六节TypeScript 类
  • RocketMQ的Docker镜像部署(以及Dashboard的部署、ACL配置)
  • 数据仓库【2】:架构
  • JavaScript函数表达式
  • LabVIEW在齿轮箱故障诊断中的应用
  • 图片转excel:“保留数字格式”在什么场景下该勾
  • SpringMVC:整合 SSM 下篇
  • [2023-年度总结]凡是过往,皆为序章
  • OpenCV之像素操作
  • Transfer Learning(迁移学习)
  • NPM 的使用技巧:简化 JavaScript 开发和依赖管理