I try to remove the element from list I am clicking on. I think I have to specify the parameters in the Todos class, but dont know what I have to add, maybe with Id's and increment the Id but how would i catch the current ID. Here is a Snipped from the debugger and a the Todo class code
Here is TODO class:
class Todo {
Todo({required this.name, required this.checked});
final String name;
bool checked;
static Todo fromJson(Map<String, dynamic> json) {
return Todo(name: json['name'], checked: json['checked']);
}
Map<String, dynamic> toJson() {
return {
'name': name,
'checked': checked,
};
}
}
class TodoItem extends StatelessWidget {
TodoItem({
required this.todo,
required this.onTap,
required this.onDelete,
}) : super(key: ObjectKey(todo));
final Todo todo;
final Function onTap;
final Function onDelete;
TextStyle? _getTextStyle(bool checked) {
if (!checked) return null;
return const TextStyle(
color: Colors.black54,
decoration: TextDecoration.lineThrough,
);
}
@override
Widget build(BuildContext context) {
return ListTile(
onTap: () {
onTap(todo);
},
leading: CircleAvatar(
child: Text(todo.name[0]),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(todo.name, style: _getTextStyle(todo.checked)),
IconButton(
onPressed: () {
print(todo.name);
onDelete();
},
icon: Icon(Icons.delete))
],
),
);
}
}
