【问题标题】:Flutter: The argument type 'Object' can't be assigned to the parameter type 'Color?'Flutter: 参数类型 \'Object\' 不能赋值给参数类型 \'Color?\'
【发布时间】:2023-02-07 18:36:43
【问题描述】:

代码是:

enter image description here

有一个奇怪的错误说 The argument type 'Color?'当我尝试分配颜色时无法分配给参数类型“Color”,这是怎么回事?

【问题讨论】:

  • 您能否包含代码-sn-p 而不是代码-图像。另一件事是你为context.theme使用自定义颜色扩展/包

标签: flutter dart


【解决方案1】:

您可以使用 Theme.of(context) 获取颜色(和其他属性)。

 color: color?? Theme.of(context).scaffoldBackgroundColor.withOpacity(.2)

并尽量不要在没有进行空检查的情况下使用!

【讨论】:

    【解决方案2】:

    颜色数据类型是颜色? 请将双数据类型更改为颜色

    【讨论】:

      猜你喜欢
      • 2022-11-27
      • 2022-09-26
      • 2021-07-06
      • 1970-01-01
      • 2022-11-17
      • 2021-08-03
      • 2023-02-06
      • 2021-06-08
      • 2021-08-21
      相关资源
      最近更新 更多