@@ -40,6 +40,21 @@ class InputTimeController extends GetxController {
4040 super .onInit ();
4141 }
4242
43+ void initTimeTextField () {
44+ AddOrUpdateAlarmController addOrUpdateAlarmController = Get .find <AddOrUpdateAlarmController >();
45+ selectedDateTime.value = addOrUpdateAlarmController.selectedTime.value;
46+
47+ isAM.value = addOrUpdateAlarmController.selectedTime.value.hour < 12 ;
48+ inputHrsController.text = settingsController.is24HrsEnabled.value
49+ ? selectedDateTime.value.hour.toString ()
50+ : (selectedDateTime.value.hour == 0
51+ ? '12'
52+ : (selectedDateTime.value.hour > 12
53+ ? (selectedDateTime.value.hour - 12 ).toString ()
54+ : selectedDateTime.value.hour.toString ()));
55+ inputMinutesController.text = selectedDateTime.value.minute.toString ().padLeft (2 , '0' );
56+ }
57+
4358
4459 final isAM = true .obs;
4560
@@ -51,6 +66,10 @@ class InputTimeController extends GetxController {
5166
5267 void changeDatePicker () {
5368 isTimePicker.value = ! isTimePicker.value;
69+
70+ if (isTimePicker.value) {
71+ initTimeTextField ();
72+ }
5473 }
5574
5675
@@ -108,18 +127,6 @@ class InputTimeController extends GetxController {
108127 AddOrUpdateAlarmController addOrUpdateAlarmController = Get .find <AddOrUpdateAlarmController >();
109128 selectedDateTime.value = addOrUpdateAlarmController.selectedTime.value;
110129
111-
112- isAM.value = addOrUpdateAlarmController.selectedTime.value.hour < 12 ;
113- inputHrsController.text = settingsController.is24HrsEnabled.value
114- ? selectedDateTime.value.hour.toString ()
115- : (selectedDateTime.value.hour == 0
116- ? '12'
117- : (selectedDateTime.value.hour > 12
118- ? (selectedDateTime.value.hour - 12 ).toString ()
119- : selectedDateTime.value.hour.toString ()));
120- inputMinutesController.text = selectedDateTime.value.minute.toString ();
121-
122-
123130 toggleIfAtBoundary ();
124131
125132 try {
@@ -135,7 +142,7 @@ class InputTimeController extends GetxController {
135142 int minute = int .parse (inputMinutesController.text);
136143 final time = TimeOfDay (hour: hour, minute: minute);
137144 DateTime today = DateTime .now ();
138- DateTime tomorrow = today.add (Duration (days: 1 ));
145+ DateTime tomorrow = today.add (const Duration (days: 1 ));
139146
140147 bool isNextDay = (time.hour == today.hour && time.minute < today.minute) || (time.hour < today.hour);
141148 bool isNextMonth = isNextDay && (today.day > tomorrow.day);
@@ -210,6 +217,9 @@ class LimitRange extends TextInputFormatter {
210217 @override
211218 TextEditingValue formatEditUpdate (TextEditingValue oldValue, TextEditingValue newValue) {
212219 try {
220+ if (newValue.text.isEmpty) {
221+ return newValue;
222+ }
213223 int value = int .parse (newValue.text);
214224 if (value < minRange) return TextEditingValue (text: minRange.toString ());
215225 else if (value > maxRange) return TextEditingValue (text: maxRange.toString ());
0 commit comments