feat(app): 添加 JournalElement 类型便利工厂方法 — text/image/sticker
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
// 日记元素数据模型 — 手写不可变类(避免 build_runner 依赖)
|
// 日记元素数据模型 — 手写不可变类(避免 build_runner 依赖)
|
||||||
|
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
@@ -153,4 +154,65 @@ class JournalElement {
|
|||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 文字元素便利工厂
|
||||||
|
factory JournalElement.createText({
|
||||||
|
required String journalId,
|
||||||
|
required String text,
|
||||||
|
required Offset position,
|
||||||
|
double fontSize = 18.0,
|
||||||
|
String fontColor = '#2D2420',
|
||||||
|
}) {
|
||||||
|
return JournalElement.create(
|
||||||
|
journalId: journalId,
|
||||||
|
elementType: ElementType.text,
|
||||||
|
positionX: position.dx,
|
||||||
|
positionY: position.dy,
|
||||||
|
content: {
|
||||||
|
'text': text,
|
||||||
|
'fontSize': fontSize,
|
||||||
|
'fontColor': fontColor,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 图片元素便利工厂
|
||||||
|
factory JournalElement.createImage({
|
||||||
|
required String journalId,
|
||||||
|
required String filePath,
|
||||||
|
required Offset position,
|
||||||
|
String? thumbnailPath,
|
||||||
|
}) {
|
||||||
|
return JournalElement.create(
|
||||||
|
journalId: journalId,
|
||||||
|
elementType: ElementType.image,
|
||||||
|
positionX: position.dx,
|
||||||
|
positionY: position.dy,
|
||||||
|
content: {
|
||||||
|
'filePath': filePath,
|
||||||
|
if (thumbnailPath != null) 'thumbnailPath': thumbnailPath,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 贴纸元素便利工厂
|
||||||
|
factory JournalElement.createSticker({
|
||||||
|
required String journalId,
|
||||||
|
required String emoji,
|
||||||
|
required Offset position,
|
||||||
|
String? stickerPackId,
|
||||||
|
String? stickerId,
|
||||||
|
}) {
|
||||||
|
return JournalElement.create(
|
||||||
|
journalId: journalId,
|
||||||
|
elementType: ElementType.sticker,
|
||||||
|
positionX: position.dx,
|
||||||
|
positionY: position.dy,
|
||||||
|
content: {
|
||||||
|
'emoji': emoji,
|
||||||
|
if (stickerPackId != null) 'stickerPackId': stickerPackId,
|
||||||
|
if (stickerId != null) 'stickerId': stickerId,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user