From fef2d629e538bccea097066a10a799335c098b77 Mon Sep 17 00:00:00 2001 From: iven Date: Mon, 1 Jun 2026 21:27:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E9=9B=86=E6=88=90=E6=96=87?= =?UTF-8?q?=E5=AD=97=E8=BE=93=E5=85=A5=E5=88=B0=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=20=E2=80=94=20TextInputOverlay=20+=20=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=A0=8F=E9=80=89=E9=A1=B9=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/editor/views/editor_page.dart | 30 ++++++++- .../editor/widgets/editor_toolbar.dart | 66 ++++++++++++++++++- 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/app/lib/features/editor/views/editor_page.dart b/app/lib/features/editor/views/editor_page.dart index e50b1da..def1fd5 100644 --- a/app/lib/features/editor/views/editor_page.dart +++ b/app/lib/features/editor/views/editor_page.dart @@ -22,6 +22,7 @@ import '../widgets/handwriting_canvas.dart'; import '../widgets/stroke_model.dart'; import '../widgets/draggable_element.dart'; import '../widgets/editor_toolbar.dart'; +import '../widgets/text_input_overlay.dart'; /// 手账编辑器页面 class EditorPage extends StatelessWidget { @@ -171,7 +172,7 @@ class _EditorView extends StatelessWidget { Expanded( child: BlocBuilder( builder: (context, state) { - return _EditorStack(state: state); + return _EditorStack(state: state, journalId: journalId); }, ), ), @@ -258,8 +259,9 @@ class _EditorView extends StatelessWidget { /// Layer 3 (顶层): 由 _EditorView 中的工具栏处理 class _EditorStack extends StatelessWidget { final EditorState state; + final String? journalId; - const _EditorStack({required this.state}); + const _EditorStack({required this.state, this.journalId}); @override Widget build(BuildContext context) { @@ -285,6 +287,30 @@ class _EditorStack extends StatelessWidget { if (state.elements.isNotEmpty) _buildElementLayer(context), + // 文字输入覆盖层(文字工具激活时显示) + if (state.activeTool == EditorTool.text) + TextInputOverlay( + onConfirmed: (text, fontSize, fontColor) { + final center = Offset( + MediaQuery.of(context).size.width / 2 - 80, + MediaQuery.of(context).size.height / 3, + ); + context.read().add(ElementAdded( + JournalElement.createText( + journalId: journalId ?? '', + text: text, + position: center, + fontSize: fontSize, + fontColor: fontColor, + ), + )); + context.read().add(ToolChanged(EditorTool.select)); + }, + onCancelled: () { + context.read().add(ToolChanged(EditorTool.select)); + }, + ), + // 空状态提示 if (state.strokes.isEmpty && state.elements.isEmpty) _buildEmptyHint(context), diff --git a/app/lib/features/editor/widgets/editor_toolbar.dart b/app/lib/features/editor/widgets/editor_toolbar.dart index d9f5fd5..aeb7c1a 100644 --- a/app/lib/features/editor/widgets/editor_toolbar.dart +++ b/app/lib/features/editor/widgets/editor_toolbar.dart @@ -129,10 +129,72 @@ class EditorToolbar extends StatelessWidget { static const _widths = [1.5, 3.0, 5.0, 8.0, 12.0]; Widget _buildOptionsRow(BuildContext context, ColorScheme colorScheme) { - if (!state.isDrawingMode) { - return const SizedBox(height: 44, child: Center(child: Text('选择元素或添加内容'))); + // 画笔模式:颜色 + 粗细 + if (state.isDrawingMode) { + return _buildBrushOptions(context, colorScheme); } + // 文字工具提示 + if (state.activeTool == EditorTool.text) { + return const SizedBox( + height: 44, + child: Center( + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(Icons.text_fields, size: 16), + SizedBox(width: 8), + Text('点击画布输入文字', style: TextStyle(fontSize: 13)), + ], + ), + ), + ); + } + + // 贴纸工具提示 + if (state.activeTool == EditorTool.sticker) { + return const SizedBox( + height: 44, + child: Center( + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(Icons.emoji_emotions_outlined, size: 16), + SizedBox(width: 8), + Text('选择一个贴纸放到日记上', style: TextStyle(fontSize: 13)), + ], + ), + ), + ); + } + + // 图片工具提示 + if (state.activeTool == EditorTool.image) { + return const SizedBox( + height: 44, + child: Center( + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(Icons.add_photo_alternate_outlined, size: 16), + SizedBox(width: 8), + Text('选择照片添加到日记', style: TextStyle(fontSize: 13)), + ], + ), + ), + ); + } + + // 选择工具 + return const SizedBox( + height: 44, + child: Center(child: Text('选择元素或添加内容')), + ); + } + + /// 画笔模式选项 — 颜色 + 粗细 + Widget _buildBrushOptions(BuildContext context, ColorScheme colorScheme) { + return SizedBox( height: 44, child: Row(