参数类型 ‘Color’ 无法赋值给参数类型 MaterialStateProperty?。

huangapple go评论66阅读模式
英文:

The argument Type 'Color' can't be assigned to the parameter type MaterialStateProperty<Color?>?

问题

你好,我正在尝试创建一个自定义的复选框小部件,以支持应用程序中的暗色和亮色主题。为此,我尝试如下操作:

static final CheckboxThemeData primaryLight = CheckboxThemeData(
  fillColor: AppColor.primary,
);

但是在AppColor.primary这一行,它给我编译时错误,提示:

"无法将类型 'Color' 的参数分配给参数类型 'MaterialStateProperty<Color?>?'"

可能是什么问题?或者我该如何解决这个问题,以创建适用于两种不同主题的通用自定义复选框?

英文:

Hello I am trying to create a custom Checkbox widget to support dark and light themes in app. For that I am trying as below:

   static final CheckboxThemeData primaryLight =CheckboxThemeData(
    fillColor:AppColor.primary 
  );

But At the line AppColor.primary, its giving me compile time error as

> "The argument Type 'Color' can't be assigned to the parameter type
> MaterialStateProperty<Color?>?"

What might be the issue? Or How can I resolve this to make the common custom Checkbox for two different themes?

答案1

得分: 1

尝试使用以下代码替代:

static final CheckboxThemeData primaryLight = CheckboxThemeData(
  fillColor: MaterialStateProperty.all(AppColor.primary),
);
英文:

try this instead

static final CheckboxThemeData primaryLight =CheckboxThemeData(
fillColor:MaterialStateProperty.all(AppColor.primary ));

答案2

得分: 1

试试这个:

static final CheckboxThemeData primaryLight = CheckboxThemeData(
    fillColor: MaterialStateProperty.all<Color>(AppColor.primary),
);
英文:

Try this:

static final CheckboxThemeData primaryLight =CheckboxThemeData(
    fillColor:MaterialStateProperty.all&lt;Color&gt;(AppColor.primary), 
);

huangapple
  • 本文由 发表于 2023年7月27日 15:59:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76777633.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定