feat:增加闪灵功能

This commit is contained in:
2025-11-09 23:52:36 +08:00
parent 7c3d35eb18
commit 98248bf1ad
13 changed files with 760 additions and 65 deletions

85
lib/models/flisp.dart Normal file
View File

@@ -0,0 +1,85 @@
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
// flutter packages pub run build_runner build
part 'flisp.g.dart';
@HiveType(typeId: 1)
class Flisp extends HiveObject {
@HiveField(0)
late int id;
@HiveField(1)
late String content;
@HiveField(2)
late int tagIndex;
@HiveField(3)
late String imageUrl;
@HiveField(4)
late String videoUrl;
@HiveField(5)
late DateTime createTime;
@HiveField(6)
late DateTime updateTime;
FlispTag get tag => FlispTag.values[tagIndex];
set tag(FlispTag value) => tagIndex = value.index;
Flisp({
int? id,
required this.content,
FlispTag tag = FlispTag.study,
required this.imageUrl,
required this.videoUrl,
DateTime? createTime,
DateTime? updateTime,
}) {
// 简单时间戳ID
this.id = id ?? DateTime.now().millisecondsSinceEpoch ~/ 1000;
this.content = content;
this.tag = tag;
this.imageUrl = imageUrl;
this.videoUrl = videoUrl;
this.createTime = createTime ?? DateTime.now();
this.updateTime = updateTime ?? DateTime.now();
}
static Flisp getEmpty() {
return Flisp(
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
content: '',
tag: FlispTag.study,
imageUrl: '',
videoUrl: '',
);
}
}
enum FlispTag {
study('学习', Color(0xFF9C27B0), Icons.school),
work('工作', Color(0xFF2196F3), Icons.work),
life('生活', Color(0xFF4CAF50), Icons.home);
final String label;
final Color color;
final IconData icon;
const FlispTag(this.label, this.color, this.icon);
}
enum FlispTab {
all('全部'),
life('生活'),
work('工作'),
study('学习');
final String label;
const FlispTab(this.label);
}

58
lib/models/flisp.g.dart Normal file
View File

@@ -0,0 +1,58 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'flisp.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class FlispAdapter extends TypeAdapter<Flisp> {
@override
final int typeId = 1;
@override
Flisp read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return Flisp(
id: fields[0] as int?,
content: fields[1] as String,
imageUrl: fields[3] as String,
videoUrl: fields[4] as String,
createTime: fields[5] as DateTime?,
updateTime: fields[6] as DateTime?,
)..tagIndex = fields[2] as int;
}
@override
void write(BinaryWriter writer, Flisp obj) {
writer
..writeByte(7)
..writeByte(0)
..write(obj.id)
..writeByte(1)
..write(obj.content)
..writeByte(2)
..write(obj.tagIndex)
..writeByte(3)
..write(obj.imageUrl)
..writeByte(4)
..write(obj.videoUrl)
..writeByte(5)
..write(obj.createTime)
..writeByte(6)
..write(obj.updateTime);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is FlispAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}