无法将参数类型“MaterialColor”分配给参数类型“MaterialStateProperty<Color>

我有一个与新的 ElevatedButtonThemeData 小部件相关的问题,基本上我想为我的应用程序中的所有 ElevatedButtons 设置背景颜色,我正在努力尝试通过执行以下操作在 ThemeData 定义中设置它:

      theme: ThemeData(
        ...
        elevatedButtonTheme: ElevatedButtonThemeData(
            style: ButtonStyle(backgroundColor: Colors.red)), // Here Im having the error
        ...
        ),
      ),

错误:

参数类型 'MaterialColor' 不能分配给参数类型 'MaterialStateProperty<Color?>?'.dartargument_type_not_assignable)

回答

阅读文档后,我找到了设置颜色的方法。

  theme: ThemeData(
    ...
    elevatedButtonTheme: ElevatedButtonThemeData(
        style: ButtonStyle(backgroundColor: MaterialStateProperty.all<Color>(Colors.red))), // Here Im having the error
    ...
    ),
  ),


以上是无法将参数类型“MaterialColor”分配给参数类型“MaterialStateProperty&lt;Color&gt;的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>