import 'package:hive/hive.dart'; import '../models/todo.dart'; import 'todo_storage.dart'; class HiveToDoStorage implements ToDoStorage { static const String _boxName = 'todoBox'; Future get _box async { return Hive.box(_boxName); } @override Future addTask(ToDo todo) async { final box = await _box; await box.add(todo.toJson()); } @override Future removeTask(int index) async { final box = await _box; await box.deleteAt(index); } @override Future updateTask(int index, ToDo todo) async { final box = await _box; await box.putAt(index, todo.toJson()); } @override Future> fetchTasks() async { final box = await _box; return box.values.map((e) => ToDo.fromJson(Map.from(e))).toList(); } }