@@ -40,6 +40,21 @@ class InputTimeController extends GetxController {
40
40
super .onInit ();
41
41
}
42
42
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
+
43
58
44
59
final isAM = true .obs;
45
60
@@ -51,6 +66,10 @@ class InputTimeController extends GetxController {
51
66
52
67
void changeDatePicker () {
53
68
isTimePicker.value = ! isTimePicker.value;
69
+
70
+ if (isTimePicker.value) {
71
+ initTimeTextField ();
72
+ }
54
73
}
55
74
56
75
@@ -108,18 +127,6 @@ class InputTimeController extends GetxController {
108
127
AddOrUpdateAlarmController addOrUpdateAlarmController = Get .find <AddOrUpdateAlarmController >();
109
128
selectedDateTime.value = addOrUpdateAlarmController.selectedTime.value;
110
129
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
-
123
130
toggleIfAtBoundary ();
124
131
125
132
try {
@@ -135,7 +142,7 @@ class InputTimeController extends GetxController {
135
142
int minute = int .parse (inputMinutesController.text);
136
143
final time = TimeOfDay (hour: hour, minute: minute);
137
144
DateTime today = DateTime .now ();
138
- DateTime tomorrow = today.add (Duration (days: 1 ));
145
+ DateTime tomorrow = today.add (const Duration (days: 1 ));
139
146
140
147
bool isNextDay = (time.hour == today.hour && time.minute < today.minute) || (time.hour < today.hour);
141
148
bool isNextMonth = isNextDay && (today.day > tomorrow.day);
@@ -210,6 +217,9 @@ class LimitRange extends TextInputFormatter {
210
217
@override
211
218
TextEditingValue formatEditUpdate (TextEditingValue oldValue, TextEditingValue newValue) {
212
219
try {
220
+ if (newValue.text.isEmpty) {
221
+ return newValue;
222
+ }
213
223
int value = int .parse (newValue.text);
214
224
if (value < minRange) return TextEditingValue (text: minRange.toString ());
215
225
else if (value > maxRange) return TextEditingValue (text: maxRange.toString ());
0 commit comments