feat(app): 编辑器未保存确认 + 日历今天按钮
Some checks failed
Main Merge / backend (push) Has been cancelled
Main Merge / frontend (push) Has been cancelled

D.2.3 编辑器未保存确认:
- _handleBack 检查 state.isDirty,有未保存修改时弹出确认对话框
- 对话框: '放弃编辑?' / '你有未保存的修改' / [继续编辑] [放弃]

D.2.4 日历今天按钮:
- _MonthNavigator 新增 onToday 回调
- 不在当前月时显示 '今天' 文字按钮,点击跳回当月
- _isCurrentMonth 辅助判断
This commit is contained in:
iven
2026-06-07 13:38:34 +08:00
parent f64355946c
commit 2f96f9a4f4
2 changed files with 59 additions and 1 deletions

View File

@@ -83,6 +83,9 @@ class _CalendarView extends StatelessWidget {
);
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.onPrevious,
required this.onNext,
this.onToday,
});
final DateTime month;
final VoidCallback onPrevious;
final VoidCallback onNext;
final VoidCallback? onToday;
@override
Widget build(BuildContext context) {
@@ -580,6 +585,22 @@ class _MonthNavigator extends StatelessWidget {
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(
width: 44,
height: 44,
@@ -607,6 +628,11 @@ class _MonthNavigator extends StatelessWidget {
];
return '${date.year}${months[date.month - 1]}';
}
bool _isCurrentMonth(DateTime date) {
final now = DateTime.now();
return date.year == now.year && date.month == now.month;
}
}
// ===== 星期标题行 =====