Flutter 错误The argument type 'Color' can't be assigned to the parameter type 'MaterialStateProperty<Color?>?'.dart(argument_type_not_assignable)
MaterialStateProperty<Color?>?和Color
- 当为TextButton等button添加颜色时,使用ButtonStyle为其添加颜色
TextButton(
onPressed: () {},
child: Text('text'),
style:
ButtonStyle(backgroundColor:Colors.white),
);
- 这样设置会报错,如题
MaterialStateProperty.all() 方法是设置点击事件所有状态下的样式。
MaterialStateProperty.resolveWith() 可拦截分别设置不同状态下的样式。
- 如果所有的状态时的颜色都相同,使用MaterialStateProperty.all(),如果不同状态要使用不同的颜色时,用MaterialStateProperty.resolveWith(),例如:
TextButton(
onPressed: () {},
child: Text('text'),
style: ButtonStyle(
//backgroundColor:MaterialStateProperty.all(Colors.white)
backgroundColor: MaterialStateProperty.resolveWith(
(states) {
if (states.contains(MaterialState.focused) &&
!states.contains(MaterialState.pressed)) {
//获取焦点时的颜色
return Colors.blue;
} else if (states.contains(MaterialState.pressed)) {
//按下时的颜色
return Colors.deepPurple;
}
//默认状态使用灰色
return Colors.grey;
},
),
),
);
参考:https://zhuanlan.zhihu.com/p/278330232
Flutter 错误The argument type 'Color' can't be assigned to the parameter type 'MaterialStateProperty<Color?>?'.dart(argument_type_not_assignable)的更多相关文章
- passing argument 3 of ‘wtk_hlv_rec_init’ discards ‘const’ qualifier from pointer target type
-Werror,编译出现如下错误: src/wtk/exam/wtk_ndx.c:154:6: error: passing argument 3 of ‘wtk_hlv_rec_init’ disc ...
- Spring错误之org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'bookService' is expected to be of type 'pw.fengya.tx.BookService' but was actually of type 'com.sun.proxy.$Proxy1
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cas ...
- 错误:Required request parameter 'XXX' for method parameter type String is not present
错误信息:Required request parameter 'XXX' for method parameter type String is not present 这种都是前端请求方式不同,后 ...
- flutter报错The type of the function literal can't be inferred because the literal has a block as its body.A value of type 'String?' can't be assigned to a variable of type 'String'.
flutter有一些报错如下 The type of the function literal can't be inferred because the literal has a block as ...
- Jekins 插件Extended Choice Parameter显示Json Parameter Type遇到的问题
在jenkins中使用Extended Choice Parameter插件用来显示自定义的多选项,尝试通过groovy script来显示,正常,但查看它的例子,发现它例子中多选是通过类型 Json ...
- default parameter value for ‘color’ must be a compile-time constant
定义了一个函数,函数有一个参数是Color类型的可选参数,想要设置其默认值为Color.Black http://stackoverflow.com/questions/2804395/c-sharp ...
- Remote error: VAR and OUT arguments must match parameter type exactly'
在XE10中 downloadfile(filename: string; out FileStream: TStream; out FileSize: int64)是没有问题的,升级到delphi ...
- Does the parameter type of the setter match the return type of the getter?
JDK 1.8, dubbo-admin版本是2.5.4-SNAPSHOT,tomcat8.5启动,报错: ERROR context.ContextLoader - Context initiali ...
- Refused to execute script from '....js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.md
目录 问题描述 解决过程 总结 问题描述 在整合 Spring Boot.Spring Security.Thymeleaf 的练习中,对页面进行调试时,发现如下错误提示: Refused to ex ...
- because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checkin
1 前言 浏览器报错误(chrome和firefox都会):because its MIME type ('text/html') is not a supported stylesheet MIME ...
随机推荐
- VulnStack-红日靶机二
红日靶机二 环境搭建 只需要把虚拟机的 host-only(仅主机)网卡改为 10.10.10.0 网段,如下配置 把 NAT 网卡,改为 192.168.96.0 网段,如下 首先恢复到 v1.3 ...
- TLB一致性维护
TLB 是页表项的物理 cache,用于加速虚拟地址到物理地址的转换.CPU 在访问一个虚拟地址时,首先会在 TLB 中查找,如果找不到对应的表项,那么就称之为 TLB miss,此时就需要去内存里查 ...
- redis - 认识 nosql 认识 redis 基础 linux安装 redis
sql和nosql的区别 1. 结构化 非结构化 2. 关联的 非关联的 3. sql查询 非 sql 4. 存储方式 磁盘 内存 5.扩展性 垂直 水平 6. 使用场景: 数据结构固定,相关业务 ...
- 小程序把html代码渲染到页面上 rich-text
<rich-text nodes="<h1>html的代码显示再小程序使用rich-text组件</h1>"></rich-text> ...
- Android复习(三)清单文件中的元素——>action、activity-alias、category、compatible-screens、data
<action> 语法: <action android:name="string" /> 包含于: <intent-filter> 说明: ...
- 使用doccano标注NER数据详细教程
使用doccano标注NER数据详细教程 说明: 首次发表日期:2024-10-12 参考资料: https://github.com/zjunlp/DeepKE/blob/main/README_T ...
- OpenGL with GLFW GLAD and CMAKE
0. 前言 首先,无论是在youtube还是网站上,许多OpenGL的环境配置都是在VS studio里配置的,个人比较喜欢使用VS code,以及Cmake. 下文给出了一个Cmake版本关于 GL ...
- Linux利用crontab命令定时任务
系统配置文件/etc 系统周期性所要执行的工作,比如写缓存数据到硬盘.日志清理等.在/etc目录下有一个crontab文件,这个就是系统任务调度的配置文件. /etc/crontab文件大概包括下面几 ...
- Octomap的学习
什么是octomap? RGBD SLAM的目的有两个:估计机器人的轨迹,并建立正确的地图.地图有很多种表达方式,比如特征点地图.网格地图.拓扑地图等等.在<一起做>系列中,我们使用的地图 ...
- Linux 基础-文本处理命令
概述 find 文件查找 grep 文本搜索 参考资料 概述 Linux 下使用 Shell 处理文本时最常用的工具有: find.grep.xargs.sort.uniq.tr.cut.paste. ...