simplified code across the app and consolidated duplicated helpers

This commit is contained in:
2026-09-27 17:29:54 +02:00
parent 3e856d0b1c
commit ee1240f71a
155 changed files with 1772 additions and 2546 deletions
@@ -13,6 +13,7 @@ import '../../../../widget/async_action_button.dart';
import '../../../../widget/demo_restricted.dart';
import '../../../../widget/focus_behaviour.dart';
import '../data/subject_color_palette.dart';
import '../data/timetable_appointment_factory.dart';
import '../subject_colors/subject_color_picker.dart';
class CustomEventEditDialog extends StatefulWidget {
@@ -72,9 +73,10 @@ class _CustomEventEditDialogState extends State<CustomEventEditDialog> {
void initState() {
super.initState();
if (_isEditing) {
final s = widget.existingEvent!.startDate;
final e = widget.existingEvent!.endDate;
_isAllDay = isAllDayConvention(s, e);
final existing = widget.existingEvent!;
final s = existing.startDate;
final e = existing.endDate;
_isAllDay = TimetableAppointmentFactory.isCustomEventAllDay(existing);
if (_isAllDay) {
_startTime = _defaultStart;
_endTime = _defaultEnd;
@@ -119,21 +121,6 @@ class _CustomEventEditDialogState extends State<CustomEventEditDialog> {
return (fromMin(start), fromMin(end));
}
/// All-day convention shared with [TimetableAppointmentFactory]: a custom
/// event is treated as all-day when its start and end both land on midnight
/// of the same day. We piggyback on this so we don't need a backend schema
/// change.
static bool isAllDayConvention(DateTime start, DateTime end) =>
start.year == end.year &&
start.month == end.month &&
start.day == end.day &&
start.hour == 0 &&
start.minute == 0 &&
start.second == 0 &&
end.hour == 0 &&
end.minute == 0 &&
end.second == 0;
Future<void> _save() async {
if (guardDemoAction(context)) return;
if (_name.text.trim().isEmpty) {
@@ -142,7 +129,7 @@ class _CustomEventEditDialogState extends State<CustomEventEditDialog> {
// All-day convention: store start and end as midnight of the chosen day.
// The factory recognises this on read.
final midnight = DateTime(_date.year, _date.month, _date.day);
final midnight = _date.dateOnly;
final startDate = _isAllDay ? midnight : _date.withTime(_startTime);
final endDate = _isAllDay ? midnight : _date.withTime(_endTime);