implemented undo button and proper sorting

This commit is contained in:
SomnusVeritas
2023-11-08 12:57:45 +01:00
parent 91ce231b04
commit c9deb726e0
4 changed files with 29 additions and 9 deletions

View File

@@ -39,7 +39,11 @@ class _TodoListState extends State<TodoList> {
tileColor: Theme.of(context).colorScheme.primaryContainer,
title: Text(todo.title),
trailing: IconButton(
onPressed: () {},
onPressed: () {
todo.done = true;
DbHelper.addOrUpdateTodo(todo);
_showSnackbar(todo);
},
icon: Icon(
Icons.check_box,
color: Theme.of(context).colorScheme.primary,
@@ -47,4 +51,18 @@ class _TodoListState extends State<TodoList> {
),
);
}
void _showSnackbar(Todo todo) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text('Todo done'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {
todo.done = false;
DbHelper.addOrUpdateTodo(todo);
}),
),
);
}
}