prashant.fepale
prashant.fepale

Reputation: 577

If statement not working even its true in flutter

Having an interesting problem here:

Simple block of code if-else bock. Inside else block if-else ladder. Though I have written a true in if still Color _orderStatus = Colors.blue; this is not working.

  1. I google it no solution.

2.If we print orderItem['order_status'].toString() == "DELIVERED" this is show true.

 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(

Upvotes: 0

Views: 1389

Answers (1)

bert
bert

Reputation: 466

I'm not a Dart programmer but I assume that:

if(true) 
{
    Color _orderStatus = Colors.blue;  
}

creates a new variable that is only valid within the curly braces scope, you probably want to change the exisiting value:

if(true) 
{
    _orderStatus = Colors.blue;  
} 

Upvotes: 6

Related Questions