feat(app): 编辑器未保存确认 + 日历今天按钮
D.2.3 编辑器未保存确认: - _handleBack 检查 state.isDirty,有未保存修改时弹出确认对话框 - 对话框: '放弃编辑?' / '你有未保存的修改' / [继续编辑] [放弃] D.2.4 日历今天按钮: - _MonthNavigator 新增 onToday 回调 - 不在当前月时显示 '今天' 文字按钮,点击跳回当月 - _isCurrentMonth 辅助判断
This commit is contained in:
@@ -554,8 +554,17 @@ class _EditorViewState extends State<_EditorView> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 返回处理
|
||||
/// 返回处理 — 有未保存修改时弹出确认
|
||||
void _handleBack(BuildContext context) {
|
||||
final bloc = context.read<EditorBloc>();
|
||||
if (bloc.state.isDirty) {
|
||||
_showDiscardDialog(context);
|
||||
} else {
|
||||
_doNavigateBack(context);
|
||||
}
|
||||
}
|
||||
|
||||
void _doNavigateBack(BuildContext context) {
|
||||
if (context.canPop()) {
|
||||
context.pop();
|
||||
} else {
|
||||
@@ -563,6 +572,29 @@ class _EditorViewState extends State<_EditorView> {
|
||||
}
|
||||
}
|
||||
|
||||
void _showDiscardDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('放弃编辑?'),
|
||||
content: const Text('你有未保存的修改,确定要离开吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('继续编辑'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(ctx);
|
||||
_doNavigateBack(context);
|
||||
},
|
||||
child: const Text('放弃'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 保存处理
|
||||
void _handleSave(BuildContext context, EditorState state) {
|
||||
widget.onSaveComplete();
|
||||
|
||||
Reference in New Issue
Block a user