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),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            );
          },
        );
      },
    );

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/881458.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

STM32 移植FATFS时遇到ff_oem2uni函数未定义问题

STM32 移植FATFS时遇到ff_oem2uni/ff_uni2oem/ff_wtoupper函数未定义问题 在移植STM32 FATFS文件系统代码时&#xff0c;完成后编译遇到如下错误&#xff1a; 经过排查分析&#xff0c;是文件没有添加完全导致的&#xff1a; 把ffunicode.c文件添加进工程就可以了&#xff…

01-Mac OS系统如何下载安装Python解释器

目录 Mac安装Python的教程 mac下载并安装python解释器 如何下载和安装最新的python解释器 访问python.org&#xff08;受国内网速的影响&#xff0c;访问速度会比较慢&#xff0c;不过也可以去我博客的资源下载&#xff09; 打开历史发布版本页面 进入下载页 鼠标拖到页面…

MongoDB解说

MongoDB 是一个流行的开源 NoSQL 数据库&#xff0c;它使用了一种被称为文档存储的数据库模型。 与传统的关系型数据库管理系统&#xff08;RDBMS&#xff09;不同&#xff0c;MongoDB 不使用表格来存储数据&#xff0c;而是使用了一种更为灵活的格式——JSON 样式的文档。 这…

论文阅读笔记:Sapiens: Foundation for Human Vision Models

Sapiens: Foundation for Human Vision Models 1 背景1.1 问题1.2 目标 2 方法3 创新点4 模块4.1 Humans-300M数据集4.2 预训练4.3 2D位姿估计4.4 身体部位分割4.5 深度估计4.6 表面法线估计 5 实验5.1 实现细节5.2 2D位姿估计5.3 身体部位分割5.4 深度估计5.5 表面法线估计5.6…

SVN笔记-SVN安装

SVN笔记-SVN安装 1、在windows下安装 SVN 1、准备svn的安装文件 下载地址&#xff1a;https://sourceforge.net/projects/win32svn/ 2、下载完成后&#xff0c;在相应的盘符中会有一个Setup-Subversion-1.8.17.msi的文件&#xff0c;目前最新的版本是1.8.17&#xff0c; 这里…

UGit:腾讯自研的Git客户端新宠

UGit 是一款专门针对腾讯内部研发环境特点量身定制的 Git 客户端&#xff0c;其目标在于大幅提升开发效率以及确保团队协作的高度流畅性。UGit 能够良好地支持 macOS 10.11 及以上版本、Apple Silicon 以及 Win64 位系统。 可以下载体验一把。 https://ugit.qq.com/zh/index.…

【CSS Tricks】如何做一个粒子效果的logo

效果展示 代码展示 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name"viewport" content"widthdevice-width, initial-scale1.0" /><title>粒子效果Logo</title>…

【图像匹配】基于Harris算法的图像匹配,matlab实现

博主简介&#xff1a;matlab图像代码项目合作&#xff08;扣扣&#xff1a;3249726188&#xff09; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 本次案例是基于基于Harris算法的图像匹配&#xff0c;用matlab实现。 一、案例背景和算法介绍 …

echarts 散点图tooltip显示一个点对应多个y值

tooltip&#xff1a;显示 tooltip: {trigger: "axis",extraCssText: max-width:50px; white-space:pre-wrap,formatter: function (params) {let arr []params.forEach(v > {arr.push(v.data[1])});return params[0].data[0]":<br>["arr.toStr…

Android 签名、空包签名 、jarsigner、apksigner

jarsigner是JDK提供的针对jar包签名的通用工具, 位于JDK/bin/jarsigner.exe apksigner是Google官方提供的针对Android apk签名及验证的专用工具, 位于Android SDK/build-tools/SDK版本/apksigner.bat jarsigner&#xff1a; jarsigner签名空包执行的命令&#xff1a; jar…

解决Hive乱码问题

在插入数据后&#xff0c;发现hive乱码 原因&#xff1a;Hive默认将存储表结构的元数据列编码设置为latin1&#xff0c;不支持中文 解决方法&#xff1a;在MySQL中修改对应Hive元数据列的编码 先查看mysql的所有字符集编码 1、先修改my.cnf 代码如下&#xff1a; vim /etc/…

weblogic CVE-2017-3506 靶场攻略

漏洞描述 Weblogic的WLS Security组件对外提供了webserver服务&#xff0c;其中使⽤了XMLDecoder来解析⽤户输⼊的XML数据&#xff0c;在解析过程中出现反序列化漏洞&#xff0c;可导致任意命令执⾏。 影响版本 受影响版本&#xff1a;WebLogic 10.3.6.0, 12.1.3.0, 12.2.1.…

YOLOv8改进 | 自定义数据集训练 | AirNet助力YOLOv8检测

目录 一、本文介绍 二、AirNet原理介绍 2.1 对比基降解编码器&#xff08;CBDE&#xff09; 2.2 降解引导修复网络&#xff08;DGRN&#xff09; 三、yolov8与AirNet结合修改教程 3.1 核心代码文件的创建与添加 3.1.1 AirNet.py文件添加 3.1.2 __init__.py文件添加 3…

AIGC时代!AI的“iPhone时刻”与投资机遇

AIGC时代&#xff01;AI的“iPhone时刻”与投资机遇 前言AI的“iPhone时刻”与投资机遇 前言 AIGC&#xff0c;也就是人工智能生成内容&#xff0c;它就像是一股汹涌的浪潮&#xff0c;席卷了整个科技世界。它的出现&#xff0c;让我们看到了人工智能的无限潜力&#xff0c;也…

微服务架构中的负载均衡与服务注册中心(Nacos)

1. 负载均衡&#xff1a;解决实际业务问题 1.1 业务场景思考 想象一个电子商务平台的微服务架构。我们有一个订单服务和多个用户服务实例。当订单服务需要调用用户服务时&#xff0c;它如何选择具体调用哪一台用户服务器&#xff1f;这就是负载均衡要解决的核心问题。 1.2 常…

HTML5好看的水果蔬菜在线商城网站源码系列模板2

文章目录 1.设计来源1.1 主界面1.2 商品列表界面1.3 商品详情界面1.4 其他界面效果 2.效果和源码2.1 动态效果2.2 源代码 源码下载 作者&#xff1a;xcLeigh 文章地址&#xff1a;https://blog.csdn.net/weixin_43151418/article/details/142059220 HTML5好看的水果蔬菜在线商城…

并查集LRU cache

并查集的定义 将n个不同的元素划分成一些不相交的集合。开始时&#xff0c;每个元素自成一个单元素集合&#xff0c;然后按一定的规律将归于同一组元素的集合合并。在此过程中要反复用到查询某一个元素归属于那个集合的运算。适合于描述这类问题的抽象数据类型称为并查集(unio…

2024华为杯研赛E题保姆级教程思路分析

E题题目&#xff1a;高速公路应急车道紧急启用模型 今年的E题设计到图像/视频处理&#xff0c;实际上&#xff0c;E题的难度相对来说较低&#xff0c;大家不用畏惧视频的处理&#xff0c;被这个吓到。实际上&#xff0c;这个不难&#xff0c;解决了视频的处理问题&#xff0c;…

Hazel 2024

不喜欢游戏的人也可以做引擎&#xff0c;比如 cherno 引擎的作用主要是有两点&#xff1a; 将数据可视化交互 当然有些引擎的功能也包含有制作数据文件&#xff0c;称之为资产 assets 不做窗口类的应用栈&#xff0c;可能要花一年才能做一个能实际使用的应用&#xff0c;只需…

笔记整理—内核!启动!—linux应用编程、网络编程部分(2)linux的文件管理策略

关于硬盘中的静态文件与inode&#xff1a;例如文件存储在扇区中&#xff0c;一个文件占用10个字节&#xff0c;一个扇区为512字节&#xff0c;这样的情况下一个扇区就只放了一个实际为10字节的文件&#xff0c;余下的502字节不可存放其他文件&#xff0c;因为扇区已经是可以访问…