Home > OS >  I have checked for null value but still get error saying I didn't checked
I have checked for null value but still get error saying I didn't checked

Time:06-20

enter image description here I already have a null check before using the value but it still give me errorenter image description here

CodePudding user response:

You can put an ! behind it to indicate you are sure it can't be null, so like

for (final value in widget.details.data.productPriceObjs!) {

If you don't like using ! you can alternatively write

var objects = widget.details.data.productPriceObjs;
if (objects != null) {
  for (final value in objects) {
  
  }
}

Somehow the compiler is fine with it when there isn't "nesting" in the check

CodePudding user response:

Put ! mark behind widget.details.data.productPriceObjs to make sure to compiler that this value is not null

For more details about null safety read here

  • Related