dart - If 语句在 flutter 中即使是 true 也不起作用

标签 dart flutter

这里有一个有趣的问题:

简单的代码块 if-else block 。在 else block 内的 if-else 阶梯。虽然我在 if still Color _orderStatus = Colors.blue; 中写了一个 true,但这是行不通的。

  1. 我用谷歌搜索没有解决方案。

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/

相关文章:

facebook - 在flutter中,如何将facebook观众作为中介网络与Admob结合?

flutter - 启动到物理设备时出现空白屏幕

flutter - Dart:警告 “info: This function has a return type of ' int',但不以return语句结尾”)

flutter - 将值传递给要在底部工作表中使用的 float 操作按钮

intellij-idea - Flutter 导入随机停止工作,原因不明

flutter - 为什么使用命令 flutter run -d chrome 无法在 chrome 上运行 Flutter 应用程序

firebase - 如何使用 Flutter 和 Firebase 实时数据库实现邀请系统

android - 使用Flutter将文本基线与列内的文本对齐

dart - Polymer.dart 1.0.0-rcx 中的事件处理程序需要什么签名

function - 如何在 Dart/Flutter 中使用另一个文件的函数?