0

What is the recommended way to check for null with the new "sound null-safety" feature of Dart , specially for the compiler to stop complaining, this doesn't work:

enter image description here

I'm obviously checking that value.data isn't null before accessing it.

Daniel Arechiga
  • 847
  • 7
  • 19
  • @Dude That might assign `null` to `profile.profilePic` which might not be allowed or desired, while the code in the screen shot ignores the case where `value.data == null` – spkersten Jan 08 '21 at 13:39

2 Answers2

2

Only local variables will get promoted.

so if you say

final temp = value.data;

if(temp != null) {
   profile.profilePic = temp.url;
}

it should work.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
-1

define

yourVariable? aNullableInt = null;