: Error: The argument type 'void Function(dynamic)' can't be assigned to the parameter type 'void Function()'. lib/widgets/tasks_list.dart:25 checkboxCallback: (checkboxState) {
^
: Error: The argument type 'void Function()' can't be assigned to the parameter type 'void Function(bool?)?'. lib/widgets/task_tile.dart:25 onChanged: checkboxCallback,
class TasksList extends StatefulWidget {
@override
State<TasksList> createState() => _TasksListState();
}
class _TasksListState extends State<TasksList> {
List<Task> tasks = [
Task(name: 'Buy milk'),
Task(name: 'Buy eggs'),
Task(name: 'Buy bread'),
];
@override
Widget build(BuildContext context) {
return ListView.builder(
itemBuilder: (context, index) {
return TaskTile(
taskTitle: tasks[index].name,
isChecked: tasks[index].isDone,
checkboxCallback: (checkboxState) {
setState(() {
tasks[index].toggleDone();
});
},
);
},
itemCount: tasks.length,
);
}
}
class TaskTile extends StatelessWidget {
final bool? isChecked;
final String? taskTitle;
final VoidCallback checkboxCallback;
TaskTile({
this.isChecked,
this.taskTitle,
required this.checkboxCallback,
});
@override
Widget build(BuildContext context) {
return CheckboxListTile(
title: Text(
taskTitle!,
style: TextStyle(
decoration: isChecked! ? TextDecoration.lineThrough : null,
),
),
activeColor: Colors.lightBlueAccent,
value: isChecked,
onChanged: checkboxCallback,
);
}
}