英文:
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<Color>(AppColor.primary),
);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论