Skip to content

Commit 195a20d

Browse files
kushchoudhary98Kush Choudhary
andauthored
fix: Alarm doesn't ring when Show Motivational Quote is turned on. (#804)
* fixed: problem with showMotivationalQuote * removed unnecessary variable --------- Co-authored-by: Kush Choudhary <kushchoudhary@Kushs-MacBook-Pro.local>
1 parent d9749b1 commit 195a20d

File tree

3 files changed

+73
-78
lines changed

3 files changed

+73
-78
lines changed

lib/app/modules/alarmRing/controllers/alarm_ring_controller.dart

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ import 'package:flutter_volume_controller/flutter_volume_controller.dart';
99

1010
import 'package:get/get.dart';
1111
import 'package:ultimate_alarm_clock/app/data/models/alarm_model.dart';
12+
import 'package:ultimate_alarm_clock/app/data/models/quote_model.dart';
1213

1314
import 'package:ultimate_alarm_clock/app/data/models/user_model.dart';
1415

1516
import 'package:ultimate_alarm_clock/app/data/providers/firestore_provider.dart';
1617
import 'package:ultimate_alarm_clock/app/data/providers/isar_provider.dart';
1718
import 'package:ultimate_alarm_clock/app/data/providers/secure_storage_provider.dart';
1819
import 'package:ultimate_alarm_clock/app/modules/settings/controllers/settings_controller.dart';
20+
import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart';
1921
import 'package:ultimate_alarm_clock/app/utils/audio_utils.dart';
22+
import 'package:ultimate_alarm_clock/app/utils/constants.dart';
2023

2124
import 'package:ultimate_alarm_clock/app/utils/utils.dart';
2225
import 'package:vibration/vibration.dart';
@@ -36,6 +39,7 @@ class AlarmControlController extends GetxController {
3639
RxBool showButton = false.obs;
3740
StreamSubscription? _sensorSubscription;
3841
HomeController homeController = Get.find<HomeController>();
42+
ThemeController themeController = Get.find<ThemeController>();
3943
SettingsController settingsController = Get.find<SettingsController>();
4044
RxBool get is24HourFormat => settingsController.is24HrsEnabled;
4145
Rx<AlarmModel> currentlyRingingAlarm = Utils.alarmModelInit.obs;
@@ -50,9 +54,6 @@ class AlarmControlController extends GetxController {
5054
RxInt guardianCoundown = 120.obs;
5155
RxBool isPreviewMode = false.obs;
5256

53-
54-
55-
5657
getNextAlarm() async {
5758
UserModel? _userModel = await SecureStorageProvider().retrieveUserModel();
5859
AlarmModel _alarmRecord = homeController.genFakeAlarmModel();
@@ -169,6 +170,68 @@ class AlarmControlController extends GetxController {
169170
});
170171
}
171172

173+
void showQuotePopup(Quote quote) {
174+
Get.defaultDialog(
175+
title: 'Motivational Quote',
176+
titlePadding: const EdgeInsets.only(
177+
top: 20,
178+
bottom: 10,
179+
),
180+
backgroundColor: themeController.secondaryBackgroundColor.value,
181+
titleStyle: TextStyle(
182+
color: themeController.primaryTextColor.value,
183+
),
184+
contentPadding: const EdgeInsets.all(20),
185+
content: Column(
186+
children: [
187+
Obx(
188+
() => Text(
189+
quote.getQuote(),
190+
style: TextStyle(
191+
color: themeController.primaryTextColor.value,
192+
),
193+
),
194+
),
195+
const SizedBox(
196+
height: 15,
197+
),
198+
Align(
199+
alignment: Alignment.centerRight,
200+
child: Obx(
201+
() => Text(
202+
quote.getAuthor(),
203+
style: TextStyle(
204+
color: themeController.primaryTextColor.value,
205+
fontWeight: FontWeight.w600,
206+
fontStyle: FontStyle.italic,
207+
),
208+
),
209+
),
210+
),
211+
const SizedBox(
212+
height: 30,
213+
),
214+
TextButton(
215+
style: ButtonStyle(
216+
backgroundColor: MaterialStateProperty.all(
217+
kprimaryColor,
218+
),
219+
),
220+
onPressed: () {
221+
Get.back();
222+
},
223+
child: Text(
224+
'Dismiss',
225+
style: TextStyle(
226+
color: themeController.secondaryTextColor.value,
227+
),
228+
),
229+
),
230+
],
231+
),
232+
);
233+
}
234+
172235
@override
173236
void onInit() async {
174237
super.onInit();
@@ -200,8 +263,6 @@ class AlarmControlController extends GetxController {
200263
});
201264
}
202265

203-
204-
205266
showButton.value = true;
206267
initialVolume = await FlutterVolumeController.getVolume(
207268
stream: AudioStream.alarm,
@@ -269,6 +330,12 @@ class AlarmControlController extends GetxController {
269330

270331
AudioUtils.playAlarm(alarmRecord: currentlyRingingAlarm.value);
271332

333+
334+
if(currentlyRingingAlarm.value.showMotivationalQuote) {
335+
Quote quote = Utils.getRandomQuote();
336+
showQuotePopup(quote);
337+
}
338+
272339
// Setting snooze duration
273340
minutes.value = currentlyRingingAlarm.value.snoozeDuration;
274341

lib/app/modules/alarmRing/views/alarm_ring_view.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ class AlarmControlView extends GetView<AlarmControlController> {
134134
visible: !controller.isSnoozing.value,
135135
child: Obx(
136136
() => Padding(
137-
padding: Get.arguments != null
138-
? const EdgeInsets.symmetric(vertical: 90.0)
139-
: EdgeInsets.zero,
137+
padding: const EdgeInsets.symmetric(vertical: 90.0),
140138
child: SizedBox(
141139
height: height * 0.07,
142140
width: width * 0.5,

lib/app/modules/home/controllers/home_controller.dart

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,6 @@ class HomeController extends GetxController {
274274
scalingFactor.value = (minFactor + (maxFactor - minFactor) * newFactor);
275275
});
276276

277-
if (Get.arguments != null) {
278-
bool showMotivationalQuote = Get.arguments.showMotivationalQuote;
279-
280-
if (showMotivationalQuote) {
281-
Quote quote = Utils.getRandomQuote();
282-
showQuotePopup(quote);
283-
}
284-
}
285277
}
286278

287279
refreshUpcomingAlarms() async {
@@ -594,68 +586,6 @@ class HomeController extends GetxController {
594586
}
595587
}
596588

597-
void showQuotePopup(Quote quote) {
598-
Get.defaultDialog(
599-
title: 'Motivational Quote',
600-
titlePadding: const EdgeInsets.only(
601-
top: 20,
602-
bottom: 10,
603-
),
604-
backgroundColor: themeController.secondaryBackgroundColor.value,
605-
titleStyle: TextStyle(
606-
color: themeController.primaryTextColor.value,
607-
),
608-
contentPadding: const EdgeInsets.all(20),
609-
content: Column(
610-
children: [
611-
Obx(
612-
() => Text(
613-
quote.getQuote(),
614-
style: TextStyle(
615-
color: themeController.primaryTextColor.value,
616-
),
617-
),
618-
),
619-
const SizedBox(
620-
height: 15,
621-
),
622-
Align(
623-
alignment: Alignment.centerRight,
624-
child: Obx(
625-
() => Text(
626-
quote.getAuthor(),
627-
style: TextStyle(
628-
color: themeController.primaryTextColor.value,
629-
fontWeight: FontWeight.w600,
630-
fontStyle: FontStyle.italic,
631-
),
632-
),
633-
),
634-
),
635-
const SizedBox(
636-
height: 30,
637-
),
638-
TextButton(
639-
style: ButtonStyle(
640-
backgroundColor: MaterialStateProperty.all(
641-
kprimaryColor,
642-
),
643-
),
644-
onPressed: () {
645-
Get.back();
646-
},
647-
child: Text(
648-
'Dismiss',
649-
style: TextStyle(
650-
color: themeController.secondaryTextColor.value,
651-
),
652-
),
653-
),
654-
],
655-
),
656-
);
657-
}
658-
659589
Future<void> swipeToDeleteAlarm(UserModel? user, AlarmModel alarm) async {
660590
AlarmModel? alarmToDelete;
661591

0 commit comments

Comments
 (0)