Skip to content

Commit 6e39f93

Browse files
authored
Bug: Resolved the Repeat Tile Bugs (#446)
* fix(repeat_tile): resolve the repeat tile bugs * style(repeat_tile): format the file using pre-commit hooks
1 parent 6558919 commit 6e39f93

File tree

2 files changed

+139
-127
lines changed

2 files changed

+139
-127
lines changed

lib/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class AddOrUpdateAlarmController extends GetxController {
137137
}
138138

139139
void setIsCustomSelected(bool value) {
140-
isCustomSelected.value = true;
140+
isCustomSelected.value = value;
141141
if (value == true) {
142142
isWeekdaysSelected.value = false;
143143
isDailySelected.value = false;
@@ -525,7 +525,9 @@ class AddOrUpdateAlarmController extends GetxController {
525525
} else {
526526
// Deleting alarm on firestore to ensure no duplicate entry
527527
await FirestoreDb.deleteAlarm(
528-
userModel.value, alarmRecord!.firestoreId!);
528+
userModel.value,
529+
alarmRecord!.firestoreId!,
530+
);
529531
createAlarm(alarmData);
530532
}
531533
}

lib/app/modules/addOrUpdateAlarm/views/repeat_tile.dart

+135-125
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import 'package:flutter/material.dart';
22
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';
53
import 'package:ultimate_alarm_clock/app/utils/constants.dart';
64
import 'package:ultimate_alarm_clock/app/utils/utils.dart';
75

@@ -168,25 +166,29 @@ class RepeatTile extends StatelessWidget {
168166
}
169167
}
170168

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+
171179
ListTile buildDailyTile({
172180
required AddOrUpdateAlarmController controller,
173181
required ThemeController themeController,
174182
}) {
175183
return ListTile(
176-
contentPadding: EdgeInsets.only(left: 10.0),
184+
contentPadding: const EdgeInsets.only(left: 10.0),
177185
title: Obx(
178186
() => InkWell(
179187
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();
187189
},
188190
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
190192
child: Row(
191193
mainAxisAlignment: MainAxisAlignment.spaceBetween,
192194
crossAxisAlignment: CrossAxisAlignment.center,
@@ -204,7 +206,7 @@ class RepeatTile extends StatelessWidget {
204206
activeColor: kprimaryColor.withOpacity(0.8),
205207
value: controller.isDailySelected.value,
206208
onChanged: (value) {
207-
// This onChanged can be empty, as we handle the tap in InkWell
209+
handleDailyTileTap();
208210
},
209211
),
210212
],
@@ -260,109 +262,122 @@ class RepeatTile extends StatelessWidget {
260262
);
261263
}
262264

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+
263362
ListTile buildCustomDaysTile({
264363
required AddOrUpdateAlarmController controller,
265364
required ThemeController themeController,
266365
required BuildContext context,
267366
}) {
268367
List<bool> repeatDays = List<bool>.filled(7, false);
269368
return ListTile(
270-
contentPadding: EdgeInsets.only(left: 10.0),
369+
contentPadding: const EdgeInsets.only(left: 10.0),
271370
title: Obx(
272371
() => InkWell(
273372
onTap: () {
274373
Utils.hapticFeedback();
275374
_storeOrPreset(repeatDays, controller.repeatDays);
276375

277376
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);
363378
},
364379
child: Padding(
365-
padding: EdgeInsets.all(8.0),
380+
padding: const EdgeInsets.all(8.0),
366381
child: Row(
367382
mainAxisAlignment: MainAxisAlignment.spaceBetween,
368383
crossAxisAlignment: CrossAxisAlignment.center,
@@ -380,9 +395,12 @@ class RepeatTile extends StatelessWidget {
380395
onChanged: (value) {
381396
Utils.hapticFeedback();
382397
controller.setIsCustomSelected(value!);
383-
384398
// Update repeatDays based on isCustomSelected value
385399
_storeOrPreset(controller.repeatDays, repeatDays);
400+
401+
if (value) {
402+
showCustomDaySelectionDialog(context: context);
403+
}
386404
},
387405
),
388406
],
@@ -393,33 +411,36 @@ class RepeatTile extends StatelessWidget {
393411
);
394412
}
395413

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+
396426
ListTile buildWeekdaysTile({
397427
required AddOrUpdateAlarmController controller,
398428
required ThemeController themeController,
399429
}) {
400430
return ListTile(
401-
contentPadding: EdgeInsets.only(left: 10.0),
431+
contentPadding: const EdgeInsets.only(left: 10.0),
402432
title: Obx(
403433
() => InkWell(
404434
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();
415436
},
416437
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
418439
child: Row(
419440
mainAxisAlignment: MainAxisAlignment.spaceBetween,
420441
crossAxisAlignment: CrossAxisAlignment.center,
421442
children: [
422-
Text(
443+
const Text(
423444
'Weekdays',
424445
),
425446
Checkbox.adaptive(
@@ -432,18 +453,7 @@ class RepeatTile extends StatelessWidget {
432453
activeColor: kprimaryColor.withOpacity(0.8),
433454
value: controller.isWeekdaysSelected.value,
434455
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();
447457
},
448458
),
449459
],

0 commit comments

Comments
 (0)