我刚刚初始化列表,一切都很好,直到我升级了颤振,因为现在我收到一个错误,说明为 The default 'List' constructor isn't available when null safety is enabled.
。我正在使用 get
和 get_storage
依赖项。
这是我收到错误的控制器类
class TodoController extends GetxController {
var todos = List<Todo>().obs;
@override
void onInit() {
List storedTodos = GetStorage().read<List>('todos');
if (!storedTodos.isNull) {
todos = storedTodos.map((e) => Todo.fromJson(e)).toList().obs;
}
ever(todos, (_) {
GetStorage().write('todos', todos.toList());
});
super.onInit();
}
}
这是我正在使用的模型类
class Todo {
String text;
bool done;
Todo({required this.text, this.done = false});
factory Todo.fromJson(Map<String, dynamic> json) =>
Todo(text: json['text'], done: json['done']);
Map<String, dynamic> toJson() => {'text': text, 'done': done};
}```
While initializing the constructor I did get an error stating as ```The parameter 'text' can't have a value of 'null' because of its type, but the implicit default value is 'null'.```
Can i get to know a bit more about this?