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

Flutter-底部选择弹窗(showModalBottomSheet)

前言

现在有个需求,需要用底部弹窗来添加定时的重复。在这里使用原生的showModalBottomSheet来实现

showModalBottomSheet的Props

名称

描述

isScrollControlled全屏还是半屏
isDismissible外部是否可以点击,false不可以点击,true可以点击,点击后消失
backgroundColor背景色,通常可以设置白色和透明
barrierColor

设置遮挡底部的半透明颜色,默认是black54,可以设置成透明的;

置外部区域的颜色

enableDrag是否可以向下拖动关闭,默认是true打开的;
shapemodel边框样式
builder构造内容

关闭弹窗

Navigator.pop(context);

完整代码

showModalBottomSheet(context: context,backgroundColor: Colors.transparent,builder: (context) {return Container(height: 600.h,padding: EdgeInsets.symmetric(horizontal: 30.w),decoration: BoxDecoration(borderRadius: BorderRadius.only(topLeft: Radius.circular(30.w),topRight: Radius.circular(30.w),),color: Colors.white,),child: Column(children: [Container(height: 110.h,child: Center(child: Text("重复".tr,style: TextStyle(fontSize: 30.sp,fontWeight: FontWeight.bold,),),),),RepeatModelItem(title: "启动一次".tr,isSelect: repeatDate.isEmpty,onPressed: () {Navigator.pop(context);},),RepeatModelItem(title: "每天".tr,isSelect: repeatDate.length == 7,onPressed: () {Navigator.pop(context);},),RepeatModelItem(title: "自定义".tr,isSelect: repeatDate.isNotEmpty && repeatDate.length < 7,onPressed: () {Navigator.pop(context);},),Container(margin: EdgeInsets.only(top: 20.h),child: TextButton(onPressed: () {Navigator.pop(context);},child: Text("取消".tr),),)],),);},);

 但是此时遇到了一个问题,在底部选择中使用多选框的是否不能选中

解决办法

使用StatefulBuilder实现局部刷新

showModalBottomSheet(isScrollControlled: true,context: context,backgroundColor: Colors.transparent,builder: (context) {//因为组件中用了多选框,要使多选框点击生效,所以这里使用了StatefulBuilder,实现局部刷新return StatefulBuilder(//弹窗内容builder: (context, setState) {return Container(height: 1050.h,padding: EdgeInsets.symmetric(horizontal: 30.w),decoration: BoxDecoration(borderRadius: BorderRadius.only(topLeft: Radius.circular(30.w),topRight: Radius.circular(30.w),),color: Colors.white,),child: Column(children: [// 标题SizedBox(height: 110.h,child: Center(child: Text("自定义".tr,style: TextStyle(fontSize: 30.sp,fontWeight: FontWeight.bold,),),),),RepeatModelItem(title: "周一".tr,isSelect: customrepeatDate[0] == 1,onPressed: () {setState(() {customrepeatDate[0] = customrepeatDate[0] == 1 ? 0 : 1;});},),RepeatModelItem(title: "周二".tr,isSelect: customrepeatDate[1] == 1,onPressed: () {setState(() {customrepeatDate[1] = customrepeatDate[1] == 1 ? 0 : 1;});},),RepeatModelItem(title: "周三".tr,isSelect: customrepeatDate[2] == 1,onPressed: () {setState(() {customrepeatDate[2] = customrepeatDate[2] == 1 ? 0 : 1;});},),RepeatModelItem(title: "周四".tr,isSelect: customrepeatDate[3] == 1,onPressed: () {setState(() {customrepeatDate[3] = customrepeatDate[3] == 1 ? 0 : 1;});},),RepeatModelItem(title: "周五".tr,isSelect: customrepeatDate[4] == 1,onPressed: () {setState(() {customrepeatDate[4] = customrepeatDate[4] == 1 ? 0 : 1;});},),RepeatModelItem(title: "周六".tr,isSelect: customrepeatDate[5] == 1,onPressed: () {setState(() {customrepeatDate[5] = customrepeatDate[5] == 1 ? 0 : 1;});},),RepeatModelItem(title: "周日".tr,isSelect: customrepeatDate[6] == 1,onPressed: () {setState(() {customrepeatDate[6] = customrepeatDate[6] == 1 ? 0 : 1;});},),// 取消、确定按钮Container(margin: EdgeInsets.only(top: 20.h),child: Row(mainAxisAlignment: MainAxisAlignment.spaceAround,children: [// 取消按钮TextButton(style: TextButton.styleFrom(minimumSize: Size(300.w, 80.h),),onPressed: () {setState(() {customrepeatDate =setcustomrepeatDate(repeatDate);});Navigator.pop(context);},child: Text("取消".tr),),// 确定按钮TextButton(style: TextButton.styleFrom(minimumSize: Size(300.w, 80.h),),onPressed: () {var repeatDate1 = [];for (var i = 0; i < 7; i++) {if (customrepeatDate[i] == 1) {repeatDate1.add(i + 1);}}// setState(() {//   repeatDate = repeatDate1;// });//用上面的方法我更新不了repeatDate数据,于是我将更新放在外面了,可能是setState是StatefulBuilder的setRepeatDate(repeatDate1);Navigator.pop(context);},child: Text("确定".tr),),],),)],),);},);},);

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • BMC 虚拟i2c访问PCA9545(switch芯片)后面的设备,为什么找不到PCA9545?
  • Leetcode 470. 用 Rand7() 实现 Rand10()
  • 【linux】kill命令
  • 【Java面向对象二】static的注意事项
  • 滑动窗口算法专题(1)
  • 【24华为杯数模研赛赛题思路已出】国赛F题第二套思路丨附参考代码丨免费分享
  • 详解数据结构中的链表结构
  • docker搭建个人网盘,支持多种格式,还能画图,一键部署
  • 软件卸载工具(windows系统)-geek
  • 虚拟机VMware安装+centos8
  • source ~/.bash_profile有什么用
  • Stylized Smooth Clouds 卡通风格化云朵包
  • js 将二进制文件流,下载为excel文件
  • 直接插入排序(C语言实现)
  • Spring 源码解读:手动实现Spring事件机制
  • CSS实用技巧干货
  • css选择器
  • Go 语言编译器的 //go: 详解
  • php ci框架整合银盛支付
  • React Native移动开发实战-3-实现页面间的数据传递
  • React 快速上手 - 06 容器组件、展示组件、操作组件
  • React-flux杂记
  • SpiderData 2019年2月16日 DApp数据排行榜
  • 高性能JavaScript阅读简记(三)
  • 给自己的博客网站加上酷炫的初音未来音乐游戏?
  • 解析 Webpack中import、require、按需加载的执行过程
  • 判断客户端类型,Android,iOS,PC
  • 前端每日实战 2018 年 7 月份项目汇总(共 29 个项目)
  • 前端学习笔记之观察者模式
  • 使用 Xcode 的 Target 区分开发和生产环境
  • 思维导图—你不知道的JavaScript中卷
  • 一些基于React、Vue、Node.js、MongoDB技术栈的实践项目
  • 译米田引理
  • 用Canvas画一棵二叉树
  • 《TCP IP 详解卷1:协议》阅读笔记 - 第六章
  • scrapy中间件源码分析及常用中间件大全
  • 大数据全解:定义、价值及挑战
  • ​直流电和交流电有什么区别为什么这个时候又要变成直流电呢?交流转换到直流(整流器)直流变交流(逆变器)​
  • # 达梦数据库知识点
  • #我与虚拟机的故事#连载20:周志明虚拟机第 3 版:到底值不值得买?
  • %3cscript放入php,跟bWAPP学WEB安全(PHP代码)--XSS跨站脚本攻击
  • ( 用例图)定义了系统的功能需求,它是从系统的外部看系统功能,并不描述系统内部对功能的具体实现
  • (007)XHTML文档之标题——h1~h6
  • (3)(3.5) 遥测无线电区域条例
  • (delphi11最新学习资料) Object Pascal 学习笔记---第5章第5节(delphi中的指针)
  • (Java入门)抽象类,接口,内部类
  • (PySpark)RDD实验实战——求商品销量排行
  • (react踩过的坑)Antd Select(设置了labelInValue)在FormItem中initialValue的问题
  • (二十一)devops持续集成开发——使用jenkins的Docker Pipeline插件完成docker项目的pipeline流水线发布
  • (附源码)springboot车辆管理系统 毕业设计 031034
  • (过滤器)Filter和(监听器)listener
  • (论文阅读40-45)图像描述1
  • (七)微服务分布式云架构spring cloud - common-service 项目构建过程
  • (贪心 + 双指针) LeetCode 455. 分发饼干
  • (一)Java算法:二分查找