1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:get/get.dart' ;
3
- import 'package:get/get_connect/http/src/utils/utils.dart' ;
4
- import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/repeat_once_tile.dart' ;
5
3
import 'package:ultimate_alarm_clock/app/utils/constants.dart' ;
6
4
import 'package:ultimate_alarm_clock/app/utils/utils.dart' ;
7
5
@@ -168,25 +166,29 @@ class RepeatTile extends StatelessWidget {
168
166
}
169
167
}
170
168
169
+ void handleDailyTileTap () {
170
+ Utils .hapticFeedback ();
171
+ controller.setIsDailySelected (! controller.isDailySelected.value);
172
+
173
+ // Update repeatDays based on isDailySelected value
174
+ for (int i = 0 ; i < controller.repeatDays.length; i++ ) {
175
+ controller.repeatDays[i] = controller.isDailySelected.value;
176
+ }
177
+ }
178
+
171
179
ListTile buildDailyTile ({
172
180
required AddOrUpdateAlarmController controller,
173
181
required ThemeController themeController,
174
182
}) {
175
183
return ListTile (
176
- contentPadding: EdgeInsets .only (left: 10.0 ),
184
+ contentPadding: const EdgeInsets .only (left: 10.0 ),
177
185
title: Obx (
178
186
() => InkWell (
179
187
onTap: () {
180
- Utils .hapticFeedback ();
181
- controller.setIsDailySelected (! controller.isDailySelected.value);
182
-
183
- // Update repeatDays based on isDailySelected value
184
- for (int i = 0 ; i < controller.repeatDays.length; i++ ) {
185
- controller.repeatDays[i] = controller.isDailySelected.value;
186
- }
188
+ handleDailyTileTap ();
187
189
},
188
190
child: Padding (
189
- padding: EdgeInsets .all (8.0 ), // Adjust the padding as needed
191
+ padding: const EdgeInsets .all (8.0 ), // Adjust the padding as needed
190
192
child: Row (
191
193
mainAxisAlignment: MainAxisAlignment .spaceBetween,
192
194
crossAxisAlignment: CrossAxisAlignment .center,
@@ -204,7 +206,7 @@ class RepeatTile extends StatelessWidget {
204
206
activeColor: kprimaryColor.withOpacity (0.8 ),
205
207
value: controller.isDailySelected.value,
206
208
onChanged: (value) {
207
- // This onChanged can be empty, as we handle the tap in InkWell
209
+ handleDailyTileTap ();
208
210
},
209
211
),
210
212
],
@@ -260,109 +262,122 @@ class RepeatTile extends StatelessWidget {
260
262
);
261
263
}
262
264
265
+ void checkIfAnyDaySelectedInCustomTile () {
266
+ controller.isCustomSelected.value = false ;
267
+
268
+ for (bool repeatDay in controller.repeatDays) {
269
+ if (controller.isCustomSelected.value) {
270
+ continue ;
271
+ } else if (repeatDay) {
272
+ controller.isCustomSelected.value = true ;
273
+ }
274
+ }
275
+ }
276
+
277
+ void showCustomDaySelectionDialog ({required BuildContext context}) {
278
+ Get .defaultDialog (
279
+ onWillPop: () async {
280
+ checkIfAnyDaySelectedInCustomTile ();
281
+ return true ;
282
+ },
283
+ titlePadding: const EdgeInsets .symmetric (vertical: 20 ),
284
+ backgroundColor: themeController.isLightMode.value
285
+ ? kLightSecondaryBackgroundColor
286
+ : ksecondaryBackgroundColor,
287
+ title: 'Days of the week' .tr,
288
+ titleStyle: TextStyle (
289
+ color: themeController.isLightMode.value
290
+ ? kLightPrimaryTextColor
291
+ : kprimaryTextColor,
292
+ ),
293
+ content: Column (
294
+ children: [
295
+ dayTile (
296
+ dayIndex: 0 ,
297
+ dayName: 'Monday' .tr,
298
+ context: context,
299
+ ),
300
+ dayTile (
301
+ dayIndex: 1 ,
302
+ dayName: 'Tuesday' .tr,
303
+ context: context,
304
+ ),
305
+ dayTile (
306
+ dayIndex: 2 ,
307
+ dayName: 'Wednesday' .tr,
308
+ context: context,
309
+ ),
310
+ dayTile (
311
+ dayIndex: 3 ,
312
+ dayName: 'Thursday' .tr,
313
+ context: context,
314
+ ),
315
+ dayTile (
316
+ dayIndex: 4 ,
317
+ dayName: 'Friday' .tr,
318
+ context: context,
319
+ ),
320
+ dayTile (
321
+ dayIndex: 5 ,
322
+ dayName: 'Saturday' .tr,
323
+ context: context,
324
+ ),
325
+ dayTile (
326
+ dayIndex: 6 ,
327
+ dayName: 'Sunday' .tr,
328
+ context: context,
329
+ ),
330
+ Padding (
331
+ padding: const EdgeInsets .only (left: 10.0 ),
332
+ child: Row (
333
+ mainAxisAlignment: MainAxisAlignment .center,
334
+ crossAxisAlignment: CrossAxisAlignment .center,
335
+ children: [
336
+ ElevatedButton (
337
+ onPressed: () {
338
+ Utils .hapticFeedback ();
339
+ checkIfAnyDaySelectedInCustomTile ();
340
+ Get .back ();
341
+ },
342
+ style: ElevatedButton .styleFrom (
343
+ backgroundColor: kprimaryColor,
344
+ ),
345
+ child: Text (
346
+ 'Done' .tr,
347
+ style: Theme .of (context).textTheme.displaySmall! .copyWith (
348
+ color: themeController.isLightMode.value
349
+ ? kLightPrimaryTextColor
350
+ : ksecondaryTextColor,
351
+ ),
352
+ ),
353
+ ),
354
+ ],
355
+ ),
356
+ ),
357
+ ],
358
+ ),
359
+ );
360
+ }
361
+
263
362
ListTile buildCustomDaysTile ({
264
363
required AddOrUpdateAlarmController controller,
265
364
required ThemeController themeController,
266
365
required BuildContext context,
267
366
}) {
268
367
List <bool > repeatDays = List <bool >.filled (7 , false );
269
368
return ListTile (
270
- contentPadding: EdgeInsets .only (left: 10.0 ),
369
+ contentPadding: const EdgeInsets .only (left: 10.0 ),
271
370
title: Obx (
272
371
() => InkWell (
273
372
onTap: () {
274
373
Utils .hapticFeedback ();
275
374
_storeOrPreset (repeatDays, controller.repeatDays);
276
375
277
376
controller.setIsCustomSelected (! controller.isCustomSelected.value);
278
- Get .defaultDialog (
279
- onWillPop: () async {
280
- // presetting values to initial state
281
- _storeOrPreset (controller.repeatDays, repeatDays);
282
- return true ;
283
- },
284
- titlePadding: const EdgeInsets .symmetric (vertical: 20 ),
285
- backgroundColor: themeController.isLightMode.value
286
- ? kLightSecondaryBackgroundColor
287
- : ksecondaryBackgroundColor,
288
- title: 'Days of the week' .tr,
289
- titleStyle: TextStyle (
290
- color: themeController.isLightMode.value
291
- ? kLightPrimaryTextColor
292
- : kprimaryTextColor,
293
- ),
294
- content: Column (
295
- children: [
296
- dayTile (
297
- dayIndex: 0 ,
298
- dayName: 'Monday' .tr,
299
- context: context,
300
- ),
301
- dayTile (
302
- dayIndex: 1 ,
303
- dayName: 'Tuesday' .tr,
304
- context: context,
305
- ),
306
- dayTile (
307
- dayIndex: 2 ,
308
- dayName: 'Wednesday' .tr,
309
- context: context,
310
- ),
311
- dayTile (
312
- dayIndex: 3 ,
313
- dayName: 'Thursday' .tr,
314
- context: context,
315
- ),
316
- dayTile (
317
- dayIndex: 4 ,
318
- dayName: 'Friday' .tr,
319
- context: context,
320
- ),
321
- dayTile (
322
- dayIndex: 5 ,
323
- dayName: 'Saturday' .tr,
324
- context: context,
325
- ),
326
- dayTile (
327
- dayIndex: 6 ,
328
- dayName: 'Sunday' .tr,
329
- context: context,
330
- ),
331
- Padding (
332
- padding: const EdgeInsets .only (left: 10.0 ),
333
- child: Row (
334
- mainAxisAlignment: MainAxisAlignment .center,
335
- crossAxisAlignment: CrossAxisAlignment .center,
336
- children: [
337
- ElevatedButton (
338
- onPressed: () {
339
- Utils .hapticFeedback ();
340
- Get .back ();
341
- },
342
- style: ElevatedButton .styleFrom (
343
- backgroundColor: kprimaryColor,
344
- ),
345
- child: Text (
346
- 'Done' .tr,
347
- style: Theme .of (context)
348
- .textTheme
349
- .displaySmall!
350
- .copyWith (
351
- color: themeController.isLightMode.value
352
- ? kLightPrimaryTextColor
353
- : ksecondaryTextColor,
354
- ),
355
- ),
356
- ),
357
- ],
358
- ),
359
- ),
360
- ],
361
- ),
362
- );
377
+ showCustomDaySelectionDialog (context: context);
363
378
},
364
379
child: Padding (
365
- padding: EdgeInsets .all (8.0 ),
380
+ padding: const EdgeInsets .all (8.0 ),
366
381
child: Row (
367
382
mainAxisAlignment: MainAxisAlignment .spaceBetween,
368
383
crossAxisAlignment: CrossAxisAlignment .center,
@@ -380,9 +395,12 @@ class RepeatTile extends StatelessWidget {
380
395
onChanged: (value) {
381
396
Utils .hapticFeedback ();
382
397
controller.setIsCustomSelected (value! );
383
-
384
398
// Update repeatDays based on isCustomSelected value
385
399
_storeOrPreset (controller.repeatDays, repeatDays);
400
+
401
+ if (value) {
402
+ showCustomDaySelectionDialog (context: context);
403
+ }
386
404
},
387
405
),
388
406
],
@@ -393,33 +411,36 @@ class RepeatTile extends StatelessWidget {
393
411
);
394
412
}
395
413
414
+ void handleWeekdayTileTap () {
415
+ Utils .hapticFeedback ();
416
+ controller.setIsWeekdaysSelected (! controller.isWeekdaysSelected.value);
417
+
418
+ // Update repeatDays based on isWeekdaysSelected value
419
+ for (int i = 0 ; i < controller.repeatDays.length; i++ ) {
420
+ // Assuming weekdays are from Monday to Friday (index 0 to 5)
421
+ controller.repeatDays[i] =
422
+ controller.isWeekdaysSelected.value && i >= 0 && i < 5 ;
423
+ }
424
+ }
425
+
396
426
ListTile buildWeekdaysTile ({
397
427
required AddOrUpdateAlarmController controller,
398
428
required ThemeController themeController,
399
429
}) {
400
430
return ListTile (
401
- contentPadding: EdgeInsets .only (left: 10.0 ),
431
+ contentPadding: const EdgeInsets .only (left: 10.0 ),
402
432
title: Obx (
403
433
() => InkWell (
404
434
onTap: () {
405
- Utils .hapticFeedback ();
406
- controller
407
- .setIsWeekdaysSelected (! controller.isWeekdaysSelected.value);
408
-
409
- // Update repeatDays based on isWeekdaysSelected value
410
- for (int i = 0 ; i < controller.repeatDays.length; i++ ) {
411
- // Assuming weekdays are from Monday to Friday (index 0 to 5)
412
- controller.repeatDays[i] =
413
- controller.isWeekdaysSelected.value && i >= 0 && i < 5 ;
414
- }
435
+ handleWeekdayTileTap ();
415
436
},
416
437
child: Padding (
417
- padding: EdgeInsets .all (8.0 ), // Adjust the padding as needed
438
+ padding: const EdgeInsets .all (8.0 ), // Adjust the padding as needed
418
439
child: Row (
419
440
mainAxisAlignment: MainAxisAlignment .spaceBetween,
420
441
crossAxisAlignment: CrossAxisAlignment .center,
421
442
children: [
422
- Text (
443
+ const Text (
423
444
'Weekdays' ,
424
445
),
425
446
Checkbox .adaptive (
@@ -432,18 +453,7 @@ class RepeatTile extends StatelessWidget {
432
453
activeColor: kprimaryColor.withOpacity (0.8 ),
433
454
value: controller.isWeekdaysSelected.value,
434
455
onChanged: (value) {
435
- Utils .hapticFeedback ();
436
- controller.setIsWeekdaysSelected (
437
- ! controller.isWeekdaysSelected.value);
438
-
439
- // Update repeatDays based on isWeekdaysSelected value
440
- for (int i = 0 ; i < controller.repeatDays.length; i++ ) {
441
- // Assuming weekdays are from Monday to Friday (index 1 to 5)
442
- controller.repeatDays[i] =
443
- controller.isWeekdaysSelected.value &&
444
- i >= 1 &&
445
- i <= 5 ;
446
- }
456
+ handleWeekdayTileTap ();
447
457
},
448
458
),
449
459
],
0 commit comments