I already have a null check before using the value but it still give me error
Asked
Active
Viewed 164 times
1

Md. Yeasin Sheikh
- 54,221
- 7
- 29
- 56

Ken
- 57
- 6
-
1Does this answer your question? [How can I make null-safety assertions to avoid using null check (!) or conditional (?) operators in Flutter?](https://stackoverflow.com/questions/71965949/how-can-i-make-null-safety-assertions-to-avoid-using-null-check-or-condition) – nvoigt Jun 20 '22 at 15:17
2 Answers
2
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

Ivo
- 18,659
- 2
- 23
- 35
0
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

Harish Sharma
- 1,189
- 1
- 8
- 19