feat:增加hive数据库

This commit is contained in:
2026-04-28 19:59:51 +08:00
parent db52de7b56
commit 3804164cfd
11 changed files with 490 additions and 52 deletions

View File

@@ -1,26 +1,54 @@
class Task {
final int id;
import 'package:hive/hive.dart';
// flutter packages pub run build_runner build
// part 'todo.g.dart';
@HiveType(typeId: 0)
class Task extends HiveObject {
@HiveField(0)
int id;
@HiveField(1)
String title;
@HiveField(2)
String? desc;
@HiveField(3)
DateTime? dueDate;
DateTime? scheduleDate;
@HiveField(4)
DateTime? scheduleTime;
@HiveField(5)
bool isCompleted;
Priority priority;
String? category;
@HiveField(6)
int priorityIndex;
@HiveField(7)
DateTime createTime;
@HiveField(8)
DateTime updateTime;
Priority get priority => Priority.values[priorityIndex];
set priority(Priority value) => priorityIndex = value.index;
Task({
int? id,
required this.title,
this.desc,
this.dueDate,
this.scheduleDate,
this.scheduleTime,
this.isCompleted = false,
this.priority = Priority.medium,
this.category,
Priority priority = Priority.medium,
DateTime? createTime,
}) : id = id ?? DateTime.timestamp().microsecond,
createTime = DateTime.now();
this.priorityIndex = priority.index,
createTime = DateTime.now(),
updateTime = DateTime.now();
}
enum Priority { low, medium, high }
enum Priority { low, medium, high }