educative.io

Error: Can't use the default List constructor. Try using List.filled instead

Hi, I’m developing “MoviesApp” in Android Studio. Though I have copied “MoviesApp”, the console warned me
“Error: Can’t use the default List constructor. Try using List.filled instead.” when following code execuded.

List<MovieModel> movies = List<MovieModel>();

Please help me. Thank you.

※I’m noob of English. I’m so sorry when my English is rude for you.

This is due to a feature in Dart known as Null Safety which makes it so that a variable cannot have a ‘null’ value unless the variable is initialized with null.
One way to mitigate this issue is that, instead of standard brackets at the end, use square brackets. []

So following code can be used instead:

List<MovieModel> movies = List<MovieModel>[];