这里有一个有趣的问题:
简单的代码块 if-else block 。在 else block 内的 if-else 阶梯。虽然我在 if still Color _orderStatus = Colors.blue;
中写了一个 true,但这是行不通的。
- 我用谷歌搜索没有解决方案。
2.如果我们打印 orderItem['order_status'].toString() == "DELIVERED"
这显示为真。
if((orderList.length -1) < index)
{
return Container(child: null);
} else {
dynamic orderItem = orderList[index];
Color _orderStatus = Colors.yellow;
if(true)
{
Color _orderStatus = Colors.blue;
} else if(orderItem['order_status'].toString() == "DELIVERED") {
Color _orderStatus = Colors.green;
} else if(orderItem['order_status'].toString() == "DISPATCHED") {
Color _orderStatus = Colors.purple;
} else if(orderItem['order_status'].toString() == "CANCEL") {
Color _orderStatus = Colors.red;
}
return Container(
最佳答案
我不是 Dart 程序员,但我认为:
if(true)
{
Color _orderStatus = Colors.blue;
}
创建一个仅在花括号范围内有效的新变量,您可能想更改现有值:
if(true)
{
_orderStatus = Colors.blue;
}
关于dart - If 语句在 flutter 中即使是 true 也不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52379014/