feat:增加hive模块
This commit is contained in:
@@ -1,48 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
class TodoItem {
|
||||
num id;
|
||||
String title;
|
||||
String content;
|
||||
bool isCompleted;
|
||||
DateTime? dueDate;
|
||||
TodoPriority priority;
|
||||
part 'todo.g.dart';
|
||||
|
||||
TodoItem({
|
||||
required this.id,
|
||||
@HiveType(typeId: 0)
|
||||
class Todo extends HiveObject {
|
||||
@HiveField(0)
|
||||
late int id;
|
||||
|
||||
@HiveField(1)
|
||||
late String title;
|
||||
|
||||
@HiveField(2)
|
||||
late String content;
|
||||
|
||||
@HiveField(3)
|
||||
late bool isCompleted;
|
||||
|
||||
@HiveField(4)
|
||||
late DateTime? dueDate;
|
||||
|
||||
@HiveField(5)
|
||||
late int priorityIndex;
|
||||
|
||||
@HiveField(6)
|
||||
late DateTime createTime;
|
||||
|
||||
@HiveField(7)
|
||||
late DateTime updateTime;
|
||||
|
||||
TodoPriority get priority => TodoPriority.values[priorityIndex];
|
||||
set priority(TodoPriority value) => priorityIndex = value.index;
|
||||
|
||||
Todo({
|
||||
int? id,
|
||||
required this.title,
|
||||
required this.content,
|
||||
this.content = '',
|
||||
this.isCompleted = false,
|
||||
this.dueDate,
|
||||
this.priority = TodoPriority.medium,
|
||||
});
|
||||
TodoPriority priority = TodoPriority.medium,
|
||||
DateTime? createTime,
|
||||
DateTime? updateTime,
|
||||
}) {
|
||||
// 简单时间戳ID
|
||||
this.id = id ?? DateTime.now().millisecondsSinceEpoch;
|
||||
this.priorityIndex = priority.index;
|
||||
this.createTime = createTime ?? DateTime.now();
|
||||
this.updateTime = updateTime ?? DateTime.now();
|
||||
}
|
||||
|
||||
TodoItem copyWith({
|
||||
num? id,
|
||||
Todo copyWith({
|
||||
String? title,
|
||||
String? content,
|
||||
bool? isCompleted,
|
||||
DateTime? dueDate,
|
||||
TodoPriority? priority,
|
||||
}) {
|
||||
return TodoItem(
|
||||
id: id ?? this.id,
|
||||
return Todo(
|
||||
id: id,
|
||||
title: title ?? this.title,
|
||||
content: content ?? this.content,
|
||||
isCompleted: isCompleted ?? this.isCompleted,
|
||||
dueDate: dueDate ?? this.dueDate,
|
||||
priority: priority ?? this.priority,
|
||||
createTime: createTime,
|
||||
updateTime: DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
static TodoItem getEmpty() {
|
||||
return TodoItem(
|
||||
id: 0,
|
||||
title: '',
|
||||
content: '',
|
||||
isCompleted: false,
|
||||
dueDate: null,
|
||||
priority: TodoPriority.medium,
|
||||
static Todo getEmpty() {
|
||||
return Todo(
|
||||
id: 0,
|
||||
title: '',
|
||||
content: '',
|
||||
isCompleted: false,
|
||||
dueDate: null,
|
||||
priority: TodoPriority.medium,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user