feat(app): 编辑器未保存确认 + 日历今天按钮
D.2.3 编辑器未保存确认: - _handleBack 检查 state.isDirty,有未保存修改时弹出确认对话框 - 对话框: '放弃编辑?' / '你有未保存的修改' / [继续编辑] [放弃] D.2.4 日历今天按钮: - _MonthNavigator 新增 onToday 回调 - 不在当前月时显示 '今天' 文字按钮,点击跳回当月 - _isCurrentMonth 辅助判断
This commit is contained in:
@@ -83,6 +83,9 @@ class _CalendarView extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
context.read<CalendarBloc>().add(CalendarMonthChanged(next));
|
context.read<CalendarBloc>().add(CalendarMonthChanged(next));
|
||||||
},
|
},
|
||||||
|
onToday: () {
|
||||||
|
context.read<CalendarBloc>().add(CalendarMonthChanged(DateTime.now()));
|
||||||
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
// 视图模式切换
|
// 视图模式切换
|
||||||
@@ -543,11 +546,13 @@ class _MonthNavigator extends StatelessWidget {
|
|||||||
required this.month,
|
required this.month,
|
||||||
required this.onPrevious,
|
required this.onPrevious,
|
||||||
required this.onNext,
|
required this.onNext,
|
||||||
|
this.onToday,
|
||||||
});
|
});
|
||||||
|
|
||||||
final DateTime month;
|
final DateTime month;
|
||||||
final VoidCallback onPrevious;
|
final VoidCallback onPrevious;
|
||||||
final VoidCallback onNext;
|
final VoidCallback onNext;
|
||||||
|
final VoidCallback? onToday;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -580,6 +585,22 @@ class _MonthNavigator extends StatelessWidget {
|
|||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
// "今天" 按钮 — 不在当前月时显示
|
||||||
|
if (onToday != null && !_isCurrentMonth(month))
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 8),
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: onToday,
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||||
|
minimumSize: Size.zero,
|
||||||
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
),
|
||||||
|
child: const Text('今天', style: TextStyle(fontSize: 13)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
const SizedBox(width: 8),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 44,
|
width: 44,
|
||||||
height: 44,
|
height: 44,
|
||||||
@@ -607,6 +628,11 @@ class _MonthNavigator extends StatelessWidget {
|
|||||||
];
|
];
|
||||||
return '${date.year}年 ${months[date.month - 1]}';
|
return '${date.year}年 ${months[date.month - 1]}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _isCurrentMonth(DateTime date) {
|
||||||
|
final now = DateTime.now();
|
||||||
|
return date.year == now.year && date.month == now.month;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 星期标题行 =====
|
// ===== 星期标题行 =====
|
||||||
|
|||||||
@@ -554,8 +554,17 @@ class _EditorViewState extends State<_EditorView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 返回处理
|
/// 返回处理 — 有未保存修改时弹出确认
|
||||||
void _handleBack(BuildContext context) {
|
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()) {
|
if (context.canPop()) {
|
||||||
context.pop();
|
context.pop();
|
||||||
} else {
|
} 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) {
|
void _handleSave(BuildContext context, EditorState state) {
|
||||||
widget.onSaveComplete();
|
widget.onSaveComplete();
|
||||||
|
|||||||
Reference in New Issue
Block a user