Home > Mobile >  DART-Flutter The default 'List' constructor isn't available when null safety is enabl
DART-Flutter The default 'List' constructor isn't available when null safety is enabl

Time:10-08

Does anybody knows how to fix this error?

Error: Can't use the default List constructor.

Future<List<EventModel>> getTaskList() async {
    var taskMapList = await getTasks();
    //var taskList = List<EventModel>();
    var taskList = new List<EventModel>();
    for (Map map in taskMapList) {
      taskList.add(EventModel.fromMap(map));
    }
    return taskList;
  }

CodePudding user response:

Please use the below code:

Future<List<EventModel>> getTaskList() async {
  var taskMapList = await getTasks();
  var taskList = <EventModel>[];
  for (Map map in taskMapList) {
    taskList.add(EventModel.fromMap(map));
  }
  return taskList;
}
  • Related