【问题标题】:The argument type 'Color' can't be assigned to the parameter type 'String'不能将参数类型 \'Color\' 分配给参数类型 \'String\'
【发布时间】:2022-12-22 06:33:03
【问题描述】:

不能将参数类型 'Color' 分配给参数类型 'String' ,我希望在状态设置为关闭时更改存储在变量 'status' 中的文本的颜色。请帮我解决这个问题..

class _todaysMealState extends State<todaysMeal> {
  String itemName = "<item_name>",
      time = "<time>",
      dayTime = "<time?>",
      status = "status",
      itemImage = "lib/images/default.png";
  Color statusColor = Colors.green;

  _todaysMealState({required this.itemName,
    required this.itemImage,
    required this.time,
    required this.dayTime,
    required this.status});

  @override
  Widget build(BuildContext context) {
    double height = MediaQuery
        .of(context)
        .size
        .height;
    double width = MediaQuery
        .of(context)
        .size
        .width;
    return Card(
      color: const Color(0xFF2B2E3F),
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(10)),
      ),
      .....
              trailing: Text(
                status == "Closed" ? statusColor = const Color(0xFFFF0000):statusColor=Colors.white,
                style:  TextStyle(
                  color: statusColor,
                  fontWeight: FontWeight.bold,
                  fontSize: 16,
                ),
              ),
              horizontalTitleGap: -15,
            ),
          ],
        ),
      )
      ,
    );
  }
}

问题在这里

trailing: Text(
                status == "Closed" ? statusColor = const Color(0xFFFF0000):statusColor=Colors.white,
                style:  TextStyle(
                  color: statusColor,
                  fontWeight: FontWeight.bold,
                  fontSize: 16,
                ),
              ),

我尽力了,剩下的就看你了,谢谢

【问题讨论】:

    标签: flutter


    【解决方案1】:
            status == "Closed" ? statusColor = const Color(0xFFFF0000):statusColor=Colors.white,
    

    在您的 Text 小部件中创建错误。它期望是一个字符串,但您提供了一个颜色对象。

    【讨论】:

      猜你喜欢
      • 2022-09-26
      • 2021-10-02
      • 2021-08-21
      • 2021-10-06
      • 2020-04-15
      • 2021-06-19
      • 2021-08-19
      • 2021-11-14
      相关资源
      最近更新 更多