-
-
Save Djsmk123/1b29755731aab1440171b849f85686a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ignore_for_file: depend_on_referenced_packages | |
import 'package:collection/collection.dart'; | |
import 'package:hydated_bloc_example/Data/Model/todo_model.dart'; | |
class TodoRepo { | |
List<TodoModel> tasks = []; | |
List<TodoModel> addTodo(TodoModel model) { | |
tasks.add(model); | |
return tasks; | |
} | |
List<TodoModel> removeTodo(int id) { | |
tasks.removeWhere((element) => element.id == id); | |
return tasks; | |
} | |
List<TodoModel> updateTask(int id, bool status) { | |
TodoModel? taskModel = | |
tasks.firstWhereOrNull((element) => element.id == id); | |
if (taskModel != null) { | |
tasks = tasks.map((task) { | |
if (task.id == id) { | |
return task.copyWith(isCompleted: status); | |
} | |
return task; | |
}).toList(); | |
} | |
return tasks; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment