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 ...
随机推荐
- 2021 IT运维巡展北京站圆满落幕,北京智和信通荣获IT运维样板工程
10月21日,以"数智转型 运维赋能"为主题的"2021(第十二届)IT运维巡展北京站"圆满落幕.会上行业专家.企业代表以及用户代表等共聚一堂,探讨数智时代下I ...
- mysql用户相关操作(转载)
mysql用户相关操作 一. 创建用户 命令: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明: username:你将创建的用户 ...
- gaussian噪声
高斯噪声 高斯噪声(Gaussian noise)是一种具有正态分布(也称作高斯分布)概率密度函数的噪声.换句话说,高斯噪声的值遵循高斯分布或者它在各个频率分量上的能量具有高斯分布.它被极其普遍地应用 ...
- PyTorch 的 Autograd
看了一篇博客,感觉写的很棒:PyTorch 的 Autograd
- .Net 反射的学习
// 反射 // 一切从 type 开始 2 种拿到 type 的方式 // 作用:动态的操作对象 获取属性 方法 特性 // 1. 拿到对象的 type // typeof(类); // 2. 拿到 ...
- netCore 封装一个检验邮箱的类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 2. 王道OS-操作系统的特征,发展和分类
1. 并发:宏观上是同时发生的,微观是交替发生的 :ps:并行:宏观和微观都是同时发生的 : ps:单核CPU同一时刻只能执行一个程序,各个程序只能并发的执行 : 多核CPU同一时刻可以同时执行多个程 ...
- 复用对评论和对文章回复的弹层 popup- vant2
基本样式: ps:当message 即输入的内容的长度为 0 的时候,按钮禁止使用 : <template> <div class="comment-post"& ...
- centos7.6源码方式安装python3.6.8
1 安装依赖包 centos7.6是没有自带python3的 [root@opgs201 ~]# cat /etc/redhat-release CentOS Linux release 7.6.18 ...
- 黑神话:悟空电脑太卡?配置不够?ToDesk云电脑入门新手教程
许多玩家在玩<黑神话:悟空>时会遭遇硬件配置不足导致的游戏卡顿.画面不流畅等问题. 其实这个难题很好解决,用ToDesk云电脑即可迎刃而解.即使你的本地电脑配置不高,也能享受到流畅的游戏体 ...