Skip to content

Instantly share code, notes, and snippets.

@Sameerkash
Created July 8, 2020 12:49
Show Gist options
  • Save Sameerkash/ab3a264d893224bee60628b463c56e83 to your computer and use it in GitHub Desktop.
Save Sameerkash/ab3a264d893224bee60628b463c56e83 to your computer and use it in GitHub Desktop.
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,
    );
  }
}
@kuyazee
Copy link

kuyazee commented Jul 24, 2020

You should create another one of this file as a dart file for better readability on the medium post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment