feat(app): 编辑器完成按钮接入分享面板 — ShareBottomSheet + sharedToClass更新
This commit is contained in:
@@ -17,6 +17,7 @@ import '../../../core/constants/design_tokens.dart';
|
||||
import '../../../data/models/journal_element.dart';
|
||||
import '../../../data/models/journal_entry.dart';
|
||||
import '../../../data/repositories/journal_repository.dart';
|
||||
import '../../../data/repositories/class_repository.dart';
|
||||
import '../bloc/editor_bloc.dart';
|
||||
import '../widgets/handwriting_canvas.dart';
|
||||
import '../widgets/stroke_model.dart';
|
||||
@@ -25,6 +26,7 @@ import '../widgets/editor_toolbar.dart';
|
||||
import '../widgets/text_input_overlay.dart';
|
||||
import '../widgets/image_picker_handler.dart';
|
||||
import '../widgets/sticker_picker_sheet.dart';
|
||||
import '../widgets/share_bottom_sheet.dart';
|
||||
|
||||
/// 手账编辑器页面
|
||||
class EditorPage extends StatelessWidget {
|
||||
@@ -55,12 +57,10 @@ class EditorPage extends StatelessWidget {
|
||||
child: _EditorView(
|
||||
journalId: journalId,
|
||||
templateId: templateId,
|
||||
savedJournalId: savedJournalId,
|
||||
repo: repo,
|
||||
onSaveComplete: () {
|
||||
if (context.canPop()) {
|
||||
context.pop();
|
||||
} else {
|
||||
context.go('/home');
|
||||
}
|
||||
_showShareSheetAndNavigate(context, repo, savedJournalId);
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -152,14 +152,73 @@ class EditorPage extends StatelessWidget {
|
||||
await repo.addElement(element);
|
||||
}
|
||||
}
|
||||
|
||||
/// 显示分享面板并在用户选择后导航
|
||||
static void _showShareSheetAndNavigate(
|
||||
BuildContext context,
|
||||
JournalRepository repo,
|
||||
String? savedJournalId,
|
||||
) {
|
||||
// 尝试获取用户的班级信息
|
||||
String? userClassId;
|
||||
String userClassName = '我的班级';
|
||||
|
||||
try {
|
||||
context.read<ClassRepository>();
|
||||
// Phase 1 简化:不等待异步调用,使用默认值
|
||||
userClassId = null; // TODO: 从 AuthBloc/ClassBloc 获取真实班级 ID
|
||||
} catch (_) {
|
||||
// ClassRepository 不可用(未注入)
|
||||
}
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (sheetContext) => ShareBottomSheet(
|
||||
classId: userClassId,
|
||||
className: userClassName,
|
||||
onDecision: (shareToClass) async {
|
||||
// 更新日记的 sharedToClass 状态
|
||||
if (savedJournalId != null) {
|
||||
try {
|
||||
final entry = await repo.getJournal(savedJournalId);
|
||||
if (entry != null) {
|
||||
await repo.updateJournal(
|
||||
entry.copyWith(sharedToClass: shareToClass),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('更新分享状态失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// 导航返回
|
||||
if (!context.mounted) return;
|
||||
if (context.canPop()) {
|
||||
context.pop();
|
||||
} else {
|
||||
context.go('/home');
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EditorView extends StatelessWidget {
|
||||
final String? journalId;
|
||||
final String? templateId;
|
||||
final String? savedJournalId;
|
||||
final JournalRepository repo;
|
||||
final VoidCallback onSaveComplete;
|
||||
|
||||
const _EditorView({this.journalId, this.templateId, required this.onSaveComplete});
|
||||
const _EditorView({
|
||||
this.journalId,
|
||||
this.templateId,
|
||||
this.savedJournalId,
|
||||
required this.repo,
|
||||
required this.onSaveComplete,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
Reference in New Issue
Block a user