Skip to content

Commit

Permalink
BugFix: Dialog cancellation conditional update (#180)
Browse files Browse the repository at this point in the history
* Add fix: reset math_tile to default onWillPop

* Add fix: reset shake_to_dismiss tile to default onWillPop

* Add fix: reset screen_activity_tile tile to default onWillPop

* Add fix: reset snooze_duration_tile tile to default onWillPop

* Add fix: reset repeat_tile to default onWillPop

* Add fix: reset to initial state onWillPop of math_challenge_tile dialogue

* Add fix: reset to initial state onWillPop of shake_to_dismiss_tile dialogue

* Add fix: reset to initial state onWillPop of screen_activity_tile dialogue

* Add fix: reset to initial state onWillPop of snooz_duration_tile dialogue

* Add fix: reset to initial state onWillPop of repeat_tile dialogue

* Add fix: refactoring math_tile code

---------

Co-authored-by: Rijuth Menon <[email protected]>
  • Loading branch information
therushdevs and MarkisDev authored Dec 10, 2023
1 parent 400180b commit 8465ab9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
23 changes: 22 additions & 1 deletion lib/app/modules/addOrUpdateAlarm/views/maths_challenge_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class MathsChallenge extends StatelessWidget {
Widget build(BuildContext context) {
var width = Get.width;
var height = Get.height;
double sliderValue;
int noOfMathQues;
bool isMathsEnabled;
return ListTile(
title: Row(
children: [
Expand Down Expand Up @@ -55,8 +58,17 @@ class MathsChallenge extends StatelessWidget {
),
onTap: () {
Utils.hapticFeedback();
controller.isMathsEnabled.value = true;
// saving initial values of sliders & numbers
isMathsEnabled = controller.isMathsEnabled.value;
sliderValue = controller.mathsSliderValue.value;
noOfMathQues = controller.numMathsQuestions.value;
Get.defaultDialog(
onWillPop: () async {
Utils.hapticFeedback();
// presetting values to initial state
_presetToInitial(isMathsEnabled, sliderValue, noOfMathQues);
return true;
},
titlePadding: const EdgeInsets.symmetric(vertical: 20),
backgroundColor: themeController.isLightMode.value
? kLightSecondaryBackgroundColor
Expand Down Expand Up @@ -142,6 +154,7 @@ class MathsChallenge extends StatelessWidget {
),
onPressed: () async {
Utils.hapticFeedback();
controller.isMathsEnabled.value = true;
Get.back();
},
),
Expand Down Expand Up @@ -206,4 +219,12 @@ class MathsChallenge extends StatelessWidget {
),
);
}

void _presetToInitial(
bool isMathsEnabled, double sliderValue, int noOfMathQues) {
controller.isMathsEnabled.value = isMathsEnabled;
controller.mathsSliderValue.value = sliderValue;
controller.numMathsQuestions.value = noOfMathQues;
controller.mathsDifficulty.value = Utils.getDifficulty(sliderValue);
}
}
15 changes: 15 additions & 0 deletions lib/app/modules/addOrUpdateAlarm/views/repeat_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ class RepeatTile extends StatelessWidget {
bool anyDaySelected =
controller.repeatDays.any((daySelected) => daySelected);

List<bool> repeatDays = List<bool>.filled(7, false);

return InkWell(
onTap: () {
Utils.hapticFeedback();
// saving initial state
_storeOrPreset(repeatDays, controller.repeatDays);
Get.defaultDialog(
onWillPop: () async {
// preseting values initial state
_storeOrPreset(controller.repeatDays, repeatDays);
return true;
},
titlePadding: const EdgeInsets.symmetric(vertical: 20),
backgroundColor: themeController.isLightMode.value
? kLightSecondaryBackgroundColor
Expand Down Expand Up @@ -127,6 +136,12 @@ class RepeatTile extends StatelessWidget {
);
}

void _storeOrPreset(List<bool> toSet, List<bool> toUse) {
for (var i = 0; i < toUse.length; i++) {
toSet[i] = toUse[i];
}
}

Widget dayTile({
required int dayIndex,
required String dayName,
Expand Down
14 changes: 12 additions & 2 deletions lib/app/modules/addOrUpdateAlarm/views/screen_activity_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@ class ScreenActivityTile extends StatelessWidget {
Widget build(BuildContext context) {
var height = Get.height;
var width = Get.width;
int activityInterval;
bool isActivityEnalbed;
return InkWell(
onTap: () {
Utils.hapticFeedback();
// storing the initial values
activityInterval = controller.activityInterval.value;
isActivityEnalbed = controller.isActivityenabled.value;
Get.defaultDialog(
onWillPop: () async {
controller.activityInterval.value = activityInterval;
controller.isActivityenabled.value = isActivityEnalbed;
return true;
},
titlePadding: const EdgeInsets.symmetric(vertical: 20),
backgroundColor: themeController.isLightMode.value
? kLightSecondaryBackgroundColor
Expand Down Expand Up @@ -119,8 +129,8 @@ class ScreenActivityTile extends StatelessWidget {
context: context,
title: 'Screen activity based cancellation',
description: 'This feature will automatically cancel'
" the alarm if you've been using your device"
' for a set number of minutes.',
" the alarm if you've been using your device"
' for a set number of minutes.',
iconData: Icons.screen_lock_portrait_outlined,
isLightMode: themeController.isLightMode.value,
);
Expand Down
15 changes: 15 additions & 0 deletions lib/app/modules/addOrUpdateAlarm/views/shake_to_dismiss_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class ShakeToDismiss extends StatelessWidget {
Widget build(BuildContext context) {
var width = Get.width;
var height = Get.height;
int shakeTimes;
bool isShakeEnabled;
return ListTile(
title: Row(
children: [
Expand Down Expand Up @@ -55,7 +57,15 @@ class ShakeToDismiss extends StatelessWidget {
),
onTap: () {
Utils.hapticFeedback();
// storing initial state
shakeTimes = controller.shakeTimes.value;
isShakeEnabled = controller.isShakeEnabled.value;
Get.defaultDialog(
onWillPop: () async {
// presetting values to initial state
_presetToInitial(shakeTimes, isShakeEnabled);
return true;
},
titlePadding: const EdgeInsets.symmetric(vertical: 20),
backgroundColor: themeController.isLightMode.value
? kLightSecondaryBackgroundColor
Expand Down Expand Up @@ -156,4 +166,9 @@ class ShakeToDismiss extends StatelessWidget {
),
);
}

void _presetToInitial(int shakeTimes, bool isShakeEnabled) {
controller.shakeTimes.value = shakeTimes;
controller.isShakeEnabled.value = isShakeEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ class SnoozeDurationTile extends StatelessWidget {

@override
Widget build(BuildContext context) {
int duration;
return InkWell(
onTap: () {
Utils.hapticFeedback();
// storing the values
duration = controller.snoozeDuration.value;
Get.defaultDialog(
onWillPop: () async {
Get.back();
// presetting the value to it's initial state
controller.snoozeDuration.value = duration;
return true;
},
titlePadding: const EdgeInsets.symmetric(vertical: 20),
backgroundColor: themeController.isLightMode.value
? kLightSecondaryBackgroundColor
Expand Down

0 comments on commit 8465ab9

Please sign in to comment.