void add(String title, String subtitle) {
var currentState = state;
if (currentState == TodoState.empty()) {
currentState = TodoState();
}
//check fot current state
if (currentState is TodoStateData) {
//object
final todo = Todo(
id: rand.nextInt(100).toString(), title: title, subtitle: subtitle);
//update
final todos = currentState.todos.toList()..add(todo);
//localstorage
read<LocalStorage>().saveTodo(todo);
//update state
state = TodoState(
todos: todos,
);
}
}
Created
July 8, 2020 12:49
-
-
Save Sameerkash/ab3a264d893224bee60628b463c56e83 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
You should create another one of this file as a dart file for better readability on the medium post.