The default ‘List’ constructor isn’t available when null safety is enabled. Try using a list literal, ‘List.filled’ or ‘List.generate’

Short answer: Instead of the pre-null-safety operations var foo = List<int>(); // Now error var bar = List<int>(n); // Now error var baz = List<int>(0); // Now error use the following: var foo = <int>[]; // Always the recommended way. var bar = List.filled(1, 0); // Not filled with `null`s. var baz = List<int>.empty(); Long … Read more

“The argument type ‘String?’ can’t be assigned to the parameter type ‘String'” when using stdin.readLineSync()

Welcome to Dart. What you are experience is the new null-safety feature (introduced with Dart 2.12.0) where variables by default cannot contain the value null. This is statically checked so you will get an error even before your program are executed. In your example the problem is the following line: var input = stdin.readLineSync(); If … Read more

“The operator can’t be unconditionally invoked because the receiver can be null” error after migrating to Dart null-safety

Dart engineer Erik Ernst says on GitHub: Type promotion is only applicable to local variables. … Promotion of an instance variable is not sound, because it could be overridden by a getter that runs a computation and returns a different object each time it is invoked. Cf. dart-lang/language#1188 for discussions about a mechanism which is … Read more