diff --git a/lib/widgets/AddNewEventDialog.dart b/lib/widgets/AddNewEventDialog.dart index 44ea5fac..2f87b16f 100644 --- a/lib/widgets/AddNewEventDialog.dart +++ b/lib/widgets/AddNewEventDialog.dart @@ -29,7 +29,8 @@ class AddNewEventDialog { final eventDayRangeTolerance = 7; DateTime? minDate; DateTime? maxDate; - bool isFormValid = true; + bool isFormValid = false; + bool hasTitleBeenEdited = false; minDate = SynchroService.globalSettingsModel!.eventStartTime!.add(Duration(days: -eventDayRangeTolerance)); maxDate = SynchroService.globalSettingsModel!.eventEndTime!.add(Duration(days: eventDayRangeTolerance)); @@ -80,7 +81,7 @@ class AddNewEventDialog { decoration: InputDecoration( labelText: "Title".tr(), labelStyle: TextStyle( - color: (title == null || title!.trim().isEmpty) + color: (hasTitleBeenEdited && (title == null || title!.trim().isEmpty)) ? ThemeConfig.redColor(context) : null, ), @@ -88,6 +89,9 @@ class AddNewEventDialog { onChanged: (value) { setState(() { title = value; + if (!hasTitleBeenEdited) { + hasTitleBeenEdited = true; + } validateForm(); }); }, diff --git a/lib/widgets/TimeDataRangePicker.dart b/lib/widgets/TimeDataRangePicker.dart index 344a7f49..23f62dfd 100644 --- a/lib/widgets/TimeDataRangePicker.dart +++ b/lib/widgets/TimeDataRangePicker.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:fstapp/services/TimeHelper.dart'; import 'package:fstapp/themeConfig.dart'; import 'package:intl/intl.dart'; +import 'package:fstapp/widgets/MouseDetector.dart'; class TimeDateRangePicker extends StatelessWidget { final DateTime? start; @@ -27,192 +28,197 @@ class TimeDateRangePicker extends StatelessWidget { final isStartValid = start != null; final isEndValid = end != null && start != null && !end!.isBefore(start!); - return Column( - children: [ - Row( + return MouseDetector( + builder: (context, mouseIsConnected) { + final timePickerMode = mouseIsConnected + ? TimePickerEntryMode.input + : TimePickerEntryMode.dial; + final datePickerMode = DatePickerEntryMode.calendar; + + return Column( children: [ - Expanded( - child: TextFormField( - readOnly: true, - decoration: InputDecoration( - labelText: "Start".tr(), - labelStyle: TextStyle( - color: isStartValid ? null : ThemeConfig.redColor(context), + Row( + children: [ + Expanded( + child: TextFormField( + readOnly: true, + decoration: InputDecoration( + labelText: "Start".tr(), + labelStyle: TextStyle( + color: isStartValid ? null : ThemeConfig.redColor(context), + ), + ), + controller: TextEditingController( + text: start != null ? TimeOfDay.fromDateTime(start!).format(context) : "", + ), + onTap: () async { + final pickedTime = await TimeHelper.showUniversalTimePicker( + context: context, + initialTime: start != null + ? TimeOfDay.fromDateTime(start!) + : TimeOfDay.now(), + initialEntryMode: timePickerMode, + ); + if (pickedTime != null) { + final pickedDateTime = DateTime( + start?.year ?? DateTime.now().year, + start?.month ?? DateTime.now().month, + start?.day ?? DateTime.now().day, + pickedTime.hour, + pickedTime.minute, + ); + onStartChanged(pickedDateTime); + if (end != null && pickedDateTime.isAfter(end!)) { + onEndChanged(DateTime( + pickedDateTime.year, + pickedDateTime.month, + pickedDateTime.day, + end!.hour, + end!.minute, + )); + } + } + }, ), ), - controller: TextEditingController( - text: start != null ? TimeOfDay.fromDateTime(start!).format(context) : "", - ), - onTap: () async { - final pickedTime = await TimeHelper.showUniversalTimePicker( - context: context, - initialTime: start != null - ? TimeOfDay.fromDateTime(start!) - : TimeOfDay.now(), - initialEntryMode: TimePickerEntryMode.input, - ); - if (pickedTime != null) { - final pickedDateTime = DateTime( - start?.year ?? DateTime.now().year, - start?.month ?? DateTime.now().month, - start?.day ?? DateTime.now().day, - pickedTime.hour, - pickedTime.minute, - ); - onStartChanged(pickedDateTime); - // Adjust end time if necessary - if (end != null && pickedDateTime.isAfter(end!)) { - onEndChanged(DateTime( - pickedDateTime.year, - pickedDateTime.month, - pickedDateTime.day, - end!.hour, - end!.minute, - )); - } - } - }, - ), - ), - const SizedBox(width: 16), - Expanded( - child: TextFormField( - readOnly: true, - decoration: InputDecoration( - labelText: "Start date".tr(), - labelStyle: TextStyle( - color: isStartValid ? null : ThemeConfig.redColor(context), + const SizedBox(width: 16), + Expanded( + child: TextFormField( + readOnly: true, + decoration: InputDecoration( + labelText: "Start date".tr(), + labelStyle: TextStyle( + color: isStartValid ? null : ThemeConfig.redColor(context), + ), + ), + controller: TextEditingController( + text: start != null ? DateFormat.yMd().format(start!) : "", + ), + onTap: () async { + final pickedDate = await showDatePicker( + context: context, + initialDate: start ?? DateTime.now(), + firstDate: minDate, + lastDate: maxDate, + initialEntryMode: datePickerMode, + ); + if (pickedDate != null) { + final pickedDateTime = DateTime( + pickedDate.year, + pickedDate.month, + pickedDate.day, + start?.hour ?? 0, + start?.minute ?? 0, + ); + onStartChanged(pickedDateTime); + if (end != null && pickedDateTime.isAfter(end!)) { + onEndChanged(DateTime( + pickedDate.year, + pickedDate.month, + pickedDate.day, + end!.hour, + end!.minute, + )); + } + } + }, ), ), - controller: TextEditingController( - text: start != null ? DateFormat.yMd().format(start!) : "", - ), - onTap: () async { - final pickedDate = await showDatePicker( - context: context, - initialDate: start ?? DateTime.now(), - firstDate: minDate, - lastDate: maxDate, - initialEntryMode: DatePickerEntryMode.calendar, - ); - if (pickedDate != null) { - final pickedDateTime = DateTime( - pickedDate.year, - pickedDate.month, - pickedDate.day, - start?.hour ?? 0, - start?.minute ?? 0, - ); - onStartChanged(pickedDateTime); - // Adjust end date if necessary - if (end != null && pickedDateTime.isAfter(end!)) { - onEndChanged(DateTime( - pickedDate.year, - pickedDate.month, - pickedDate.day, - end!.hour, - end!.minute, - )); - } - } - }, - ), + ], ), - ], - ), - const SizedBox(height: 16), - Row( - children: [ - Expanded( - child: TextFormField( - readOnly: true, - decoration: InputDecoration( - labelText: "End".tr(), - labelStyle: TextStyle( - color: isEndValid ? null : ThemeConfig.redColor(context), + const SizedBox(height: 16), + Row( + children: [ + Expanded( + child: TextFormField( + readOnly: true, + decoration: InputDecoration( + labelText: "End".tr(), + labelStyle: TextStyle( + color: isEndValid ? null : ThemeConfig.redColor(context), + ), + ), + controller: TextEditingController( + text: end != null ? TimeOfDay.fromDateTime(end!).format(context) : "", + ), + onTap: () async { + final pickedTime = await TimeHelper.showUniversalTimePicker( + context: context, + initialTime: end != null + ? TimeOfDay.fromDateTime(end!) + : TimeOfDay.now(), + initialEntryMode: timePickerMode, + ); + if (pickedTime != null) { + final pickedDateTime = DateTime( + end?.year ?? DateTime.now().year, + end?.month ?? DateTime.now().month, + end?.day ?? DateTime.now().day, + pickedTime.hour, + pickedTime.minute, + ); + onEndChanged(pickedDateTime); + if (start != null && pickedDateTime.isBefore(start!)) { + onStartChanged(DateTime( + pickedDateTime.year, + pickedDateTime.month, + pickedDateTime.day, + start!.hour, + start!.minute, + )); + } + } + }, ), ), - controller: TextEditingController( - text: end != null ? TimeOfDay.fromDateTime(end!).format(context) : "", - ), - onTap: () async { - final pickedTime = await TimeHelper.showUniversalTimePicker( - context: context, - initialTime: end != null - ? TimeOfDay.fromDateTime(end!) - : TimeOfDay.now(), - initialEntryMode: TimePickerEntryMode.input, - ); - if (pickedTime != null) { - final pickedDateTime = DateTime( - end?.year ?? DateTime.now().year, - end?.month ?? DateTime.now().month, - end?.day ?? DateTime.now().day, - pickedTime.hour, - pickedTime.minute, - ); - onEndChanged(pickedDateTime); - // Adjust start time if necessary - if (start != null && pickedDateTime.isBefore(start!)) { - onStartChanged(DateTime( - pickedDateTime.year, - pickedDateTime.month, - pickedDateTime.day, - start!.hour, - start!.minute, - )); - } - } - }, - ), - ), - const SizedBox(width: 16), - Expanded( - child: TextFormField( - readOnly: true, - decoration: InputDecoration( - labelText: "End date".tr(), - labelStyle: TextStyle( - color: isEndValid ? null : ThemeConfig.redColor(context), + const SizedBox(width: 16), + Expanded( + child: TextFormField( + readOnly: true, + decoration: InputDecoration( + labelText: "End date".tr(), + labelStyle: TextStyle( + color: isEndValid ? null : ThemeConfig.redColor(context), + ), + ), + controller: TextEditingController( + text: end != null ? DateFormat.yMd().format(end!) : "", + ), + onTap: () async { + final pickedDate = await showDatePicker( + context: context, + initialDate: end ?? DateTime.now(), + firstDate: minDate, + lastDate: maxDate, + initialEntryMode: datePickerMode, + ); + if (pickedDate != null) { + final pickedDateTime = DateTime( + pickedDate.year, + pickedDate.month, + pickedDate.day, + end?.hour ?? 0, + end?.minute ?? 0, + ); + onEndChanged(pickedDateTime); + if (start != null && pickedDateTime.isBefore(start!)) { + onStartChanged(DateTime( + pickedDate.year, + pickedDate.month, + pickedDate.day, + start!.hour, + start!.minute, + )); + } + } + }, ), ), - controller: TextEditingController( - text: end != null ? DateFormat.yMd().format(end!) : "", - ), - onTap: () async { - final pickedDate = await showDatePicker( - context: context, - initialDate: end ?? DateTime.now(), - firstDate: minDate, - lastDate: maxDate, - initialEntryMode: DatePickerEntryMode.calendar, - ); - if (pickedDate != null) { - final pickedDateTime = DateTime( - pickedDate.year, - pickedDate.month, - pickedDate.day, - end?.hour ?? 0, - end?.minute ?? 0, - ); - onEndChanged(pickedDateTime); - // Adjust start date if necessary - if (start != null && pickedDateTime.isBefore(start!)) { - onStartChanged(DateTime( - pickedDate.year, - pickedDate.month, - pickedDate.day, - start!.hour, - start!.minute, - )); - } - } - }, - ), + ], ), ], - ), - ], + ); + }, ); } -} \ No newline at end of file +}