I'm using Dart 2.15.1 with default setting null safety enabled. I don't understand, why this does not work:
main() {
int test;
if (1 > 0) { test = 42; }
print(test); // <- The non-nullable local variable 'test' must be assigned before it can be used.
}
while this works without any error:
main() {
int test;
if (true) { test = 42; }
print(test); // <- no error here
}
It's not a big thing, I can certainly implement a workaround, but I'm curious why dart behaves like this.
Thank you for your help.