【问题标题】:The argument type 'MaterialColor' can't be assigned to the parameter type 'Paint'参数类型“MaterialColor”不能分配给参数类型“Paint”
【发布时间】:2018-12-26 19:12:07
【问题描述】:

我想将背景颜色设置为红色,但 TextStyle 小部件下没有 'backgroundColor' 属性。

有背景属性,但我无法设置背景的值。它显示错误&错误是

参数类型“MaterialColor”不能分配给参数 输入“油漆”

我知道这个错误是合理的。 但是背景属性的值应该是多少?

我搜索但遗憾的是找不到:( 我可以将背景设置为background: Paint(),背景变为黑色。但我需要红色背景。 背景的值应该是多少?

谢谢

【问题讨论】:

    标签: android dart flutter flutter-layout


    【解决方案1】:

    只需将Paintcolor 属性设置为Colors.red

    Text(
      "Hello",
      style: TextStyle(background: Paint()..color = Colors.red),
    ),
    

    【讨论】:

    • 哦! "Paint()..color = Colors.red" ,称为级联方法。我只是学习这些新东西。谢谢
    【解决方案2】:

    建议您直接使用backgroundColor 属性,而不是使用background 来定义颜色,如下所示:

       Text(
            'Wow',
            style: TextStyle(backgroundColor: Colors.red),
          ),
    

    【讨论】:

      猜你喜欢
      • 2021-08-21
      • 2021-08-27
      • 2021-01-09
      • 2020-09-24
      • 2021-08-22
      • 2021-01-05
      • 2021-06-19
      • 2021-12-13
      • 2021-08-19
      相关资源
      最近更新 更多