// mark a todo as done
void toggle(Todo todo) {
final currentState = state;
if (currentState is TodoStateData) {
final todos = currentState.todos.map((t) {
if (t == todo) {
var to = t.copyWith(
isDone: !t.isDone,
);
read<LocalStorage>().updateTodo(to);
return to;
}
return t;
}).toList();
state = TodoState(
todos: todos,
);
}
}
// Delete a todo
void delete(Todo todo) {
final currentState = state;
if (currentState is TodoStateData) {
var list = currentState.todos.where((t) => t != todo).toList();
if (list.isEmpty) {
state = TodoState.empty();
} else {
state = TodoState(todos: list);
read<LocalStorage>().deleteTodos(todo);
}
}
}
}
Created
July 10, 2020 13:21
-
-
Save Sameerkash/7305f9dc853ced34994527ade4a2e08e to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment