feat:增加提醒事项
This commit is contained in:
58
lib/models/reminder.dart
Normal file
58
lib/models/reminder.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:hive/hive.dart';
|
||||
// flutter packages pub run build_runner build
|
||||
part 'reminder.g.dart';
|
||||
|
||||
@HiveType(typeId: 1)
|
||||
class Reminder extends HiveObject {
|
||||
@HiveField(0)
|
||||
late int id;
|
||||
|
||||
@HiveField(1)
|
||||
late String title;
|
||||
|
||||
@HiveField(2)
|
||||
late String content;
|
||||
|
||||
@HiveField(3)
|
||||
late DateTime scheduledTime;
|
||||
|
||||
@HiveField(4)
|
||||
late DateTime createTime;
|
||||
|
||||
@HiveField(5)
|
||||
late DateTime updateTime;
|
||||
|
||||
Reminder({
|
||||
int? id,
|
||||
required this.title,
|
||||
required this.content,
|
||||
required this.scheduledTime,
|
||||
DateTime? createTime,
|
||||
DateTime? updateTime,
|
||||
}) {
|
||||
// 简单时间戳ID
|
||||
this.id = id ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
this.createTime = createTime ?? DateTime.now();
|
||||
this.updateTime = updateTime ?? DateTime.now();
|
||||
}
|
||||
|
||||
Reminder copyWith({String? title, String? content, DateTime? scheduledTime}) {
|
||||
return Reminder(
|
||||
id: id,
|
||||
title: title ?? this.title,
|
||||
content: content ?? this.content,
|
||||
scheduledTime: scheduledTime ?? this.scheduledTime,
|
||||
createTime: createTime,
|
||||
updateTime: DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
static Reminder getEmpty() {
|
||||
return Reminder(
|
||||
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
title: '日常提醒',
|
||||
content: '',
|
||||
scheduledTime: DateTime.now().add(Duration(minutes: 5)),
|
||||
);
|
||||
}
|
||||
}
|
||||
56
lib/models/reminder.g.dart
Normal file
56
lib/models/reminder.g.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'reminder.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class ReminderAdapter extends TypeAdapter<Reminder> {
|
||||
@override
|
||||
final int typeId = 1;
|
||||
|
||||
@override
|
||||
Reminder read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return Reminder(
|
||||
id: fields[0] as int?,
|
||||
title: fields[1] as String,
|
||||
content: fields[2] as String,
|
||||
scheduledTime: fields[3] as DateTime,
|
||||
createTime: fields[4] as DateTime?,
|
||||
updateTime: fields[5] as DateTime?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, Reminder obj) {
|
||||
writer
|
||||
..writeByte(6)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
..write(obj.title)
|
||||
..writeByte(2)
|
||||
..write(obj.content)
|
||||
..writeByte(3)
|
||||
..write(obj.scheduledTime)
|
||||
..writeByte(4)
|
||||
..write(obj.createTime)
|
||||
..writeByte(5)
|
||||
..write(obj.updateTime);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ReminderAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -30,6 +30,7 @@ class Todo extends HiveObject {
|
||||
late DateTime updateTime;
|
||||
|
||||
TodoPriority get priority => TodoPriority.values[priorityIndex];
|
||||
|
||||
set priority(TodoPriority value) => priorityIndex = value.index;
|
||||
|
||||
Todo({
|
||||
@@ -43,7 +44,7 @@ class Todo extends HiveObject {
|
||||
DateTime? updateTime,
|
||||
}) {
|
||||
// 简单时间戳ID
|
||||
this.id = id ?? DateTime.now().millisecondsSinceEpoch;
|
||||
this.id = id ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
this.priorityIndex = priority.index;
|
||||
this.createTime = createTime ?? DateTime.now();
|
||||
this.updateTime = updateTime ?? DateTime.now();
|
||||
@@ -70,8 +71,8 @@ class Todo extends HiveObject {
|
||||
|
||||
static Todo getEmpty() {
|
||||
return Todo(
|
||||
id: DateTime.now().millisecondsSinceEpoch,
|
||||
title: '',
|
||||
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
title: '日常待办',
|
||||
content: '',
|
||||
isCompleted: false,
|
||||
dueDate: null,
|
||||
|
||||
@@ -17,7 +17,7 @@ class TodoAdapter extends TypeAdapter<Todo> {
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return Todo(
|
||||
id: fields[0] as int,
|
||||
id: fields[0] as int?,
|
||||
title: fields[1] as String,
|
||||
content: fields[2] as String,
|
||||
isCompleted: fields[3] as bool,
|
||||
|
||||
Reference in New Issue
Block a user