Closed
Description
I testing the following class in dartpad using Dart SDK 2.12.0-51.0.dev
class Coffee {
List<String>? types;
Coffee(this.types);
void printType() {
if (types != null) {
print(types[0]);
}
}
}
The compiler complains that types
may be null in the print statement.
"An expression whose value can be 'null' must be null-checked before it can be dereferenced - line 16"
I realize the docs say
" The analyzer can’t model the flow of your whole application, so it can’t predict the values of global variables or class fields."
but I wonder in the case were we explicitly check if a class var is not null is supposed to be or could be handled?