feat:增加hive模块
This commit is contained in:
24
lib/service/todo_service.dart
Normal file
24
lib/service/todo_service.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:flisp_app/models/todo.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
class TodoService {
|
||||
static const String boxName = 'todos';
|
||||
|
||||
Box<Todo> get box => Hive.box<Todo>(boxName);
|
||||
|
||||
Future<void> addTodo(Todo todo) async {
|
||||
await box.add(todo);
|
||||
}
|
||||
|
||||
List<Todo> getAllTodos() {
|
||||
return box.values.toList();
|
||||
}
|
||||
|
||||
Future<void> updateTodo(Todo todo) async {
|
||||
await todo.save();
|
||||
}
|
||||
|
||||
Future<void> deleteTodo(Todo todo) async {
|
||||
await todo.delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user