我正在使用新的dart 版本<;2.13.0-107.0.开发>;启用空安全.
使用此任务列表:
List<Task> tasks = [
Task(name: 'find a way to live happy'),
Task(name: 'Listen to music!!!'),
Task(name: 'Live in the other world till ur power is off'),
];
当我try 在ListView.builder构造函数中使用它时,如下所示:
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: tasks.length,
itemBuilder: (context, index) {
TaskTile(
taskTitle: tasks[index].name,
isChecked: tasks[index].isDone,
checkboxCallback: (bool? checkboxState) {
setState(() {
tasks[index].toggleDone();
});
},
);
},
);
}
我得到这个错误:
100
运行日志(log)中出现以下错误:
100
有关详细信息,任务类定义如下:
class Task {
String name;
bool isDone;
Task({this.name = '', this.isDone = false});
void toggleDone() {
isDone = !isDone;
}
}