feat:增加闪灵功能
This commit is contained in:
39
lib/service/flisp_service.dart
Normal file
39
lib/service/flisp_service.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:flisp_app/models/flisp.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
class FlispService {
|
||||
static const String boxName = 'flisps';
|
||||
|
||||
Box<Flisp> get box => Hive.box<Flisp>(boxName);
|
||||
|
||||
Future<bool> addFlisp(Flisp flisp) async {
|
||||
try {
|
||||
await box.add(flisp);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
List<Flisp> getAllFlisps() {
|
||||
return box.values.toList();
|
||||
}
|
||||
|
||||
Future<bool> updateFlisp(Flisp flisp) async {
|
||||
try {
|
||||
await flisp.save();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> deleteFlisp(Flisp flisp) async {
|
||||
try {
|
||||
await flisp.delete();
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,6 @@ class TodoService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> updateTodoCompletion(Todo todo, bool isCompleted) async {
|
||||
todo.isCompleted = isCompleted;
|
||||
return await updateTodo(todo);
|
||||
}
|
||||
|
||||
Future<bool> deleteTodo(Todo todo) async {
|
||||
try {
|
||||
await todo.delete();
|
||||
|
||||
Reference in New Issue
Block a user