diff --git a/lib/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart b/lib/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart index baf81538..13ff80c7 100644 --- a/lib/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart +++ b/lib/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart @@ -20,6 +20,7 @@ import 'package:ultimate_alarm_clock/app/data/models/ringtone_model.dart'; import 'package:ultimate_alarm_clock/app/modules/home/controllers/home_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; import 'package:ultimate_alarm_clock/app/utils/audio_utils.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; import 'package:uuid/uuid.dart'; @@ -195,11 +196,10 @@ class AddOrUpdateAlarmController extends GetxController { ' and Ignore batter optimization.', ), actions: [ - TextButton( - style: TextButton.styleFrom( - backgroundColor: kprimaryColor, - ), - child: const Text('Cancel', style: TextStyle(color: Colors.black)), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Cancel'.tr, onPressed: () { Get.back(); }, @@ -207,14 +207,10 @@ class AddOrUpdateAlarmController extends GetxController { const SizedBox( width: 10, ), - TextButton( - style: TextButton.styleFrom( - backgroundColor: kprimaryColor, - ), - child: const Text( - 'Grant Permission', - style: TextStyle(color: Colors.black), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Grant Permission'.tr, onPressed: () async { Get.back(); @@ -285,19 +281,13 @@ class AddOrUpdateAlarmController extends GetxController { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - TextButton( + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Cancel'.tr, onPressed: () { Get.back(); }, - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - 'Cancel'.tr, - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: kprimaryBackgroundColor, - ), - ), ), OutlinedButton( onPressed: () { @@ -368,11 +358,10 @@ class AddOrUpdateAlarmController extends GetxController { 'To ensure timely alarm dismissal, this app requires access to your location. Your location will be accessed in the background at the scheduled alarm time.', ), actions: [ - TextButton( - style: TextButton.styleFrom( - backgroundColor: kprimaryColor, - ), - child: const Text('Cancel', style: TextStyle(color: Colors.black)), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Cancel'.tr, onPressed: () { Get.back(result: false); }, @@ -380,11 +369,10 @@ class AddOrUpdateAlarmController extends GetxController { const SizedBox( width: 10, ), - TextButton( - style: TextButton.styleFrom( - backgroundColor: kprimaryColor, - ), - child: const Text('Allow', style: TextStyle(color: Colors.black)), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Allow'.tr, onPressed: () { Get.back(result: true); }, @@ -462,61 +450,32 @@ class AddOrUpdateAlarmController extends GetxController { ? Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - TextButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - 'Save', - style: Theme.of(Get.context!) - .textTheme - .displaySmall! - .copyWith( - color: themeController.secondaryTextColor.value, - ), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Save'.tr, onPressed: () { qrValue.value = detectedQrValue.value; isQrEnabled.value = true; Get.back(); }, ), - TextButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - 'Retake', - style: Theme.of(Get.context!) - .textTheme - .displaySmall! - .copyWith( - color: themeController.secondaryTextColor.value, - ), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: + 'Retake'.tr, onPressed: () async { qrController.dispose(); restartQRCodeController(true); }, ), if (isQrEnabled.value) - TextButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - 'Disable', - style: Theme.of(Get.context!) - .textTheme - .displaySmall! - .copyWith( - color: - themeController.secondaryTextColor.value, - ), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: + 'Disable'.tr, onPressed: () { isQrEnabled.value = false; qrValue.value = ''; @@ -570,18 +529,10 @@ class AddOrUpdateAlarmController extends GetxController { showQRDialog(); } }, - confirm: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(kprimaryColor), - ), - child: Obx( - () => Text( - 'OK', - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: themeController.secondaryTextColor.value, - ), - ), - ), + confirm: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'OK'.tr, onPressed: () async { Get.back(); // Close the alert box PermissionStatus permissionStatus = @@ -592,24 +543,14 @@ class AddOrUpdateAlarmController extends GetxController { } }, ), - cancel: Obx( - () => TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - themeController.primaryTextColor.value.withOpacity(0.5), - ), - ), - child: Text( - 'Cancel', - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: themeController.primaryTextColor.value, - ), - ), + cancel: UACTextButton( + isButtonPrimary: false, + isTextPrimary: true, + text: 'Cancel'.tr, onPressed: () { Get.back(); // Close the alert box }, ), - ), ); } else { showQRDialog(); diff --git a/lib/app/modules/addOrUpdateAlarm/views/add_or_update_alarm_view.dart b/lib/app/modules/addOrUpdateAlarm/views/add_or_update_alarm_view.dart index 3a33c30b..a93497f5 100644 --- a/lib/app/modules/addOrUpdateAlarm/views/add_or_update_alarm_view.dart +++ b/lib/app/modules/addOrUpdateAlarm/views/add_or_update_alarm_view.dart @@ -2,9 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; -import 'package:permission_handler/permission_handler.dart'; import 'package:numberpicker/numberpicker.dart'; -import 'package:ultimate_alarm_clock/app/data/models/alarm_model.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/controllers/input_time_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/alarm_id_tile.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/alarm_offset_tile.dart'; @@ -20,6 +18,7 @@ import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/qr_bar_c import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/quote_tile.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/repeat_once_tile.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/repeat_tile.dart'; +import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/save_or_update_button.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/screen_activity_tile.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/setting_selector.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/shake_to_dismiss_tile.dart'; @@ -30,6 +29,7 @@ import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/views/weather_ import 'package:ultimate_alarm_clock/app/modules/settings/controllers/settings_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; import '../controllers/add_or_update_alarm_controller.dart'; import 'alarm_date_tile.dart'; @@ -133,23 +133,10 @@ class AddOrUpdateAlarmView extends GetView { ), ), ), - TextButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all(kprimaryColor), - ), - child: Obx( - () => Text( - 'Go back'.tr, - style: Theme.of(context) - .textTheme - .displaySmall! - .copyWith( - color: themeController - .secondaryTextColor.value, - ), - ), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Go back'.tr, onPressed: () { Utils.hapticFeedback(); Get.back(); @@ -1027,173 +1014,9 @@ class AddOrUpdateAlarmView extends GetView { ), (controller.mutexLock.value == true) ? const SizedBox() - : Padding( - padding: const EdgeInsets.all(18.0), - child: SizedBox( - height: height * 0.06, - width: width * 0.8, - child: TextButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - (controller.alarmRecord.value.alarmID == '') - ? 'Save'.tr - : 'Update'.tr, - style: Theme.of(context) - .textTheme - .displaySmall! - .copyWith( - color: themeController.secondaryTextColor.value, - ), - ), - onPressed: () async { - Utils.hapticFeedback(); - await controller.checkOverlayPermissionAndNavigate(); - - if ((await Permission.systemAlertWindow.isGranted) && - (await Permission - .ignoreBatteryOptimizations.isGranted)) { - if (!controller.homeController.isProfile.value) { - if (controller.userModel.value != null) { - controller.offsetDetails[ - controller.userModel.value!.id] = { - 'offsettedTime': Utils.timeOfDayToString( - TimeOfDay.fromDateTime( - Utils.calculateOffsetAlarmTime( - controller.selectedTime.value, - controller.isOffsetBefore.value, - controller.offsetDuration.value, - ), - ), - ), - 'offsetDuration': - controller.offsetDuration.value, - 'isOffsetBefore': - controller.isOffsetBefore.value, - }; - } else { - controller.offsetDetails.value = {}; - } - AlarmModel alarmRecord = AlarmModel( - deleteAfterGoesOff: - controller.deleteAfterGoesOff.value, - snoozeDuration: controller.snoozeDuration.value, - volMax: controller.volMax.value, - volMin: controller.volMin.value, - gradient: controller.gradient.value, - offsetDetails: controller.offsetDetails, - label: controller.label.value, - note: controller.note.value, - showMotivationalQuote: - controller.showMotivationalQuote.value, - isOneTime: controller.isOneTime.value, - lastEditedUserId: - controller.lastEditedUserId.value, - mutexLock: controller.mutexLock.value, - alarmID: controller.alarmID, - ownerId: controller.ownerId.value, - ownerName: controller.ownerName.value, - activityInterval: - controller.activityInterval.value * 60000, - days: controller.repeatDays.toList(), - alarmTime: Utils.timeOfDayToString( - TimeOfDay.fromDateTime( - controller.selectedTime.value, - ), - ), - mainAlarmTime: Utils.timeOfDayToString( - TimeOfDay.fromDateTime( - controller.selectedTime.value, - ), - ), - intervalToAlarm: Utils.getMillisecondsToAlarm( - DateTime.now(), - controller.selectedTime.value, - ), - isActivityEnabled: - controller.isActivityenabled.value, - minutesSinceMidnight: Utils.timeOfDayToInt( - TimeOfDay.fromDateTime( - controller.selectedTime.value, - ), - ), - isLocationEnabled: - controller.isLocationEnabled.value, - weatherTypes: Utils.getIntFromWeatherTypes( - controller.selectedWeather.toList(), - ), - isWeatherEnabled: - controller.isWeatherEnabled.value, - location: Utils.geoPointToString( - Utils.latLngToGeoPoint( - controller.selectedPoint.value, - ), - ), - isSharedAlarmEnabled: - controller.isSharedAlarmEnabled.value, - isQrEnabled: controller.isQrEnabled.value, - qrValue: controller.qrValue.value, - isMathsEnabled: controller.isMathsEnabled.value, - numMathsQuestions: - controller.numMathsQuestions.value, - mathsDifficulty: - controller.mathsDifficulty.value.index, - isShakeEnabled: controller.isShakeEnabled.value, - shakeTimes: controller.shakeTimes.value, - isPedometerEnabled: - controller.isPedometerEnabled.value, - numberOfSteps: controller.numberOfSteps.value, - ringtoneName: - controller.customRingtoneName.value, - activityMonitor: - controller.isActivityMonitorenabled.value, - alarmDate: controller.selectedDate.value - .toString() - .substring(0, 11), - profile: controller - .homeController.selectedProfile.value, - isGuardian: controller.isGuardian.value, - guardianTimer: 0, - guardian: controller - .contactTextEditingController.text, - isCall: controller.isCall.value, - ringOn: controller.isFutureDate.value, - ); - - // Adding offset details to the database if - // its a shared alarm - if (controller.isSharedAlarmEnabled.value) { - alarmRecord.offsetDetails = - controller.offsetDetails; - alarmRecord.mainAlarmTime = - Utils.timeOfDayToString( - TimeOfDay.fromDateTime( - controller.selectedTime.value, - ), - ); - } - try { - if (controller.alarmRecord.value.alarmID == - '') { - await controller.createAlarm(alarmRecord); - } else { - AlarmModel updatedAlarmModel = - controller.updatedAlarmModel(); - await controller - .updateAlarm(updatedAlarmModel); - } - } catch (e) { - debugPrint(e.toString()); - } - } else { - controller.createProfile(); - } - } - }, - ), - ), + : SaveOrUpdateButton( + controller: controller, + themeController: themeController, ), ], ), diff --git a/lib/app/modules/addOrUpdateAlarm/views/alarm_id_tile.dart b/lib/app/modules/addOrUpdateAlarm/views/alarm_id_tile.dart index df0865d4..88c685f4 100644 --- a/lib/app/modules/addOrUpdateAlarm/views/alarm_id_tile.dart +++ b/lib/app/modules/addOrUpdateAlarm/views/alarm_id_tile.dart @@ -3,7 +3,7 @@ import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; -import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; class AlarmIDTile extends StatelessWidget { @@ -79,21 +79,10 @@ class AlarmIDTile extends StatelessWidget { ), Padding( padding: const EdgeInsets.symmetric(vertical: 10.0), - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - kprimaryColor, - ), - ), - child: Text( - 'Okay'.tr, - style: Theme.of(context) - .textTheme - .displaySmall! - .copyWith( - color: themeController.secondaryTextColor.value, - ), - ), + child: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Okay'.tr, onPressed: () { Utils.hapticFeedback(); Get.back(); diff --git a/lib/app/modules/addOrUpdateAlarm/views/label_tile.dart b/lib/app/modules/addOrUpdateAlarm/views/label_tile.dart index 64d2acdd..4c26be3c 100644 --- a/lib/app/modules/addOrUpdateAlarm/views/label_tile.dart +++ b/lib/app/modules/addOrUpdateAlarm/views/label_tile.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; -import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; class LabelTile extends StatelessWidget { @@ -92,17 +92,10 @@ class LabelTile extends StatelessWidget { }, ), buttonColor: themeController.secondaryBackgroundColor.value, - confirm: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - 'Save'.tr, - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: - themeController.secondaryTextColor.value, - ), - ), + confirm: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Save'.tr, onPressed: () { Utils.hapticFeedback(); controller.label.value = controller.labelController.text; diff --git a/lib/app/modules/addOrUpdateAlarm/views/location_activity_tile.dart b/lib/app/modules/addOrUpdateAlarm/views/location_activity_tile.dart index 414dafb3..7b5bb20a 100644 --- a/lib/app/modules/addOrUpdateAlarm/views/location_activity_tile.dart +++ b/lib/app/modules/addOrUpdateAlarm/views/location_activity_tile.dart @@ -4,6 +4,7 @@ import 'package:get/get.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; class LocationTile extends StatelessWidget { @@ -129,16 +130,10 @@ class LocationTile extends StatelessWidget { ), ), const SizedBox(height: 10), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - 'Save', - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: themeController.secondaryTextColor.value, - ), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Save'.tr, onPressed: () { Utils.hapticFeedback(); Get.back(); diff --git a/lib/app/modules/addOrUpdateAlarm/views/maths_challenge_tile.dart b/lib/app/modules/addOrUpdateAlarm/views/maths_challenge_tile.dart index dd69cfa9..d5144652 100644 --- a/lib/app/modules/addOrUpdateAlarm/views/maths_challenge_tile.dart +++ b/lib/app/modules/addOrUpdateAlarm/views/maths_challenge_tile.dart @@ -4,6 +4,7 @@ import 'package:numberpicker/numberpicker.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; class MathsChallenge extends StatelessWidget { @@ -141,18 +142,10 @@ class MathsChallenge extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - TextButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - 'Save'.tr, - style: - Theme.of(context).textTheme.displaySmall!.copyWith( - color: themeController.secondaryTextColor.value, - ), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Save'.tr, onPressed: () async { Utils.hapticFeedback(); if (controller.numMathsQuestions.value != 0) { @@ -166,19 +159,10 @@ class MathsChallenge extends StatelessWidget { SizedBox( width: width * 0.05, ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - themeController.primaryTextColor.value.withOpacity(0.5), - ), - ), - child: Text( - 'Cancel'.tr, - style: - Theme.of(context).textTheme.displaySmall!.copyWith( - color: themeController.primaryTextColor.value, - ), - ), + UACTextButton( + isButtonPrimary: false, + isTextPrimary: true, + text: 'Cancel'.tr, onPressed: () { Utils.hapticFeedback(); controller.isMathsEnabled.value = false; diff --git a/lib/app/modules/addOrUpdateAlarm/views/note.dart b/lib/app/modules/addOrUpdateAlarm/views/note.dart index 74cac234..2444b5c6 100644 --- a/lib/app/modules/addOrUpdateAlarm/views/note.dart +++ b/lib/app/modules/addOrUpdateAlarm/views/note.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; -import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; class NoteTile extends StatelessWidget { @@ -91,16 +91,10 @@ class NoteTile extends StatelessWidget { }, ), buttonColor: themeController.secondaryBackgroundColor.value, - confirm: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - 'Save'.tr, - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: themeController.secondaryTextColor.value, - ), - ), + confirm: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Save'.tr, onPressed: () { Utils.hapticFeedback(); controller.note.value = controller.noteController.text; diff --git a/lib/app/modules/addOrUpdateAlarm/views/repeat_tile.dart b/lib/app/modules/addOrUpdateAlarm/views/repeat_tile.dart index 1c2a3432..2950cc1f 100644 --- a/lib/app/modules/addOrUpdateAlarm/views/repeat_tile.dart +++ b/lib/app/modules/addOrUpdateAlarm/views/repeat_tile.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; import '../../settings/controllers/theme_controller.dart'; @@ -62,26 +63,14 @@ class RepeatTile extends StatelessWidget { child: Padding( padding: const EdgeInsets.only( left: 25, right: 25, bottom: 25), - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - kprimaryColor, - ), - ), + child: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, onPressed: () { Utils.hapticFeedback(); Get.back(); }, - child: Text( - 'Done', - style: Theme.of(context) - .textTheme - .displaySmall! - .copyWith( - color: controller.themeController - .secondaryTextColor.value, - ), - ), + text: 'Done'.tr, ), ), ), diff --git a/lib/app/modules/addOrUpdateAlarm/views/save_or_update_button.dart b/lib/app/modules/addOrUpdateAlarm/views/save_or_update_button.dart new file mode 100644 index 00000000..91046c61 --- /dev/null +++ b/lib/app/modules/addOrUpdateAlarm/views/save_or_update_button.dart @@ -0,0 +1,160 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:permission_handler/permission_handler.dart'; +import 'package:ultimate_alarm_clock/app/data/models/alarm_model.dart'; +import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; +import 'package:ultimate_alarm_clock/app/utils/utils.dart'; + +import '../../settings/controllers/theme_controller.dart'; + +class SaveOrUpdateButton extends StatelessWidget { + final AddOrUpdateAlarmController controller; + final ThemeController themeController; + + const SaveOrUpdateButton({ + super.key, + required this.controller, + required this.themeController, + }); + + @override + Widget build(BuildContext context) { + double height = MediaQuery.of(context).size.height; + double width = MediaQuery.of(context).size.width; + return Padding( + padding: const EdgeInsets.all(18.0), + child: SizedBox( + height: height * 0.06, + width: width * 0.8, + child: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: (controller.alarmRecord.value.alarmID == '') + ? 'Save'.tr + : 'Update'.tr, + onPressed: () async { + Utils.hapticFeedback(); + await controller.checkOverlayPermissionAndNavigate(); + + if ((await Permission.systemAlertWindow.isGranted) && + (await Permission.ignoreBatteryOptimizations.isGranted)) { + if (!controller.homeController.isProfile.value) { + if (controller.userModel.value != null) { + controller.offsetDetails[controller.userModel.value!.id] = { + 'offsettedTime': Utils.timeOfDayToString( + TimeOfDay.fromDateTime( + Utils.calculateOffsetAlarmTime( + controller.selectedTime.value, + controller.isOffsetBefore.value, + controller.offsetDuration.value, + ), + ), + ), + 'offsetDuration': controller.offsetDuration.value, + 'isOffsetBefore': controller.isOffsetBefore.value, + }; + } else { + controller.offsetDetails.value = {}; + } + AlarmModel alarmRecord = AlarmModel( + deleteAfterGoesOff: controller.deleteAfterGoesOff.value, + snoozeDuration: controller.snoozeDuration.value, + volMax: controller.volMax.value, + volMin: controller.volMin.value, + gradient: controller.gradient.value, + offsetDetails: controller.offsetDetails, + label: controller.label.value, + note: controller.note.value, + showMotivationalQuote: controller.showMotivationalQuote.value, + isOneTime: controller.isOneTime.value, + lastEditedUserId: controller.lastEditedUserId.value, + mutexLock: controller.mutexLock.value, + alarmID: controller.alarmID, + ownerId: controller.ownerId.value, + ownerName: controller.ownerName.value, + activityInterval: controller.activityInterval.value * 60000, + days: controller.repeatDays.toList(), + alarmTime: Utils.timeOfDayToString( + TimeOfDay.fromDateTime( + controller.selectedTime.value, + ), + ), + mainAlarmTime: Utils.timeOfDayToString( + TimeOfDay.fromDateTime( + controller.selectedTime.value, + ), + ), + intervalToAlarm: Utils.getMillisecondsToAlarm( + DateTime.now(), + controller.selectedTime.value, + ), + isActivityEnabled: controller.isActivityenabled.value, + minutesSinceMidnight: Utils.timeOfDayToInt( + TimeOfDay.fromDateTime( + controller.selectedTime.value, + ), + ), + isLocationEnabled: controller.isLocationEnabled.value, + weatherTypes: Utils.getIntFromWeatherTypes( + controller.selectedWeather.toList(), + ), + isWeatherEnabled: controller.isWeatherEnabled.value, + location: Utils.geoPointToString( + Utils.latLngToGeoPoint( + controller.selectedPoint.value, + ), + ), + isSharedAlarmEnabled: controller.isSharedAlarmEnabled.value, + isQrEnabled: controller.isQrEnabled.value, + qrValue: controller.qrValue.value, + isMathsEnabled: controller.isMathsEnabled.value, + numMathsQuestions: controller.numMathsQuestions.value, + mathsDifficulty: controller.mathsDifficulty.value.index, + isShakeEnabled: controller.isShakeEnabled.value, + shakeTimes: controller.shakeTimes.value, + isPedometerEnabled: controller.isPedometerEnabled.value, + numberOfSteps: controller.numberOfSteps.value, + ringtoneName: controller.customRingtoneName.value, + activityMonitor: controller.isActivityMonitorenabled.value, + alarmDate: + controller.selectedDate.value.toString().substring(0, 11), + profile: controller.homeController.selectedProfile.value, + isGuardian: controller.isGuardian.value, + guardianTimer: 0, + guardian: controller.contactTextEditingController.text, + isCall: controller.isCall.value, + ringOn: controller.isFutureDate.value, + ); + + // Adding offset details to the database if + // its a shared alarm + if (controller.isSharedAlarmEnabled.value) { + alarmRecord.offsetDetails = controller.offsetDetails; + alarmRecord.mainAlarmTime = Utils.timeOfDayToString( + TimeOfDay.fromDateTime( + controller.selectedTime.value, + ), + ); + } + try { + if (controller.alarmRecord.value.alarmID == '') { + await controller.createAlarm(alarmRecord); + } else { + AlarmModel updatedAlarmModel = + controller.updatedAlarmModel(); + await controller.updateAlarm(updatedAlarmModel); + } + } catch (e) { + debugPrint(e.toString()); + } + } else { + controller.createProfile(); + } + } + }, + ), + ), + ); + } +} diff --git a/lib/app/modules/addOrUpdateAlarm/views/shared_alarm_tile.dart b/lib/app/modules/addOrUpdateAlarm/views/shared_alarm_tile.dart index a614eb81..45dd2076 100644 --- a/lib/app/modules/addOrUpdateAlarm/views/shared_alarm_tile.dart +++ b/lib/app/modules/addOrUpdateAlarm/views/shared_alarm_tile.dart @@ -5,6 +5,7 @@ import 'package:get/get.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; class SharedAlarm extends StatelessWidget { @@ -85,27 +86,14 @@ class SharedAlarm extends StatelessWidget { ), SizedBox( width: width, - child: TextButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all( - kprimaryColor, - ), - ), + child: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Understood'.tr, onPressed: () { Utils.hapticFeedback(); Get.back(); }, - child: Text( - 'Understood'.tr, - style: Theme.of(context) - .textTheme - .displaySmall! - .copyWith( - color: themeController - .secondaryTextColor.value, - ), - ), ), ), ], diff --git a/lib/app/modules/addOrUpdateAlarm/views/weather_tile.dart b/lib/app/modules/addOrUpdateAlarm/views/weather_tile.dart index fd80c1c9..671e8440 100644 --- a/lib/app/modules/addOrUpdateAlarm/views/weather_tile.dart +++ b/lib/app/modules/addOrUpdateAlarm/views/weather_tile.dart @@ -3,6 +3,7 @@ import 'package:get/get.dart'; import 'package:ultimate_alarm_clock/app/modules/addOrUpdateAlarm/controllers/add_or_update_alarm_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; class WeatherTile extends StatelessWidget { @@ -121,26 +122,14 @@ class WeatherTile extends StatelessWidget { ), SizedBox( width: width, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - kprimaryColor, - ), - ), + child: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Understood'.tr, onPressed: () { Utils.hapticFeedback(); Get.back(); }, - child: Text( - 'Understood'.tr, - style: Theme.of(context) - .textTheme - .displaySmall! - .copyWith( - color: themeController - .secondaryTextColor.value, - ), - ), ), ), ], diff --git a/lib/app/modules/alarmChallenge/views/qr_challenge_view.dart b/lib/app/modules/alarmChallenge/views/qr_challenge_view.dart index bb1ffce1..668b170f 100644 --- a/lib/app/modules/alarmChallenge/views/qr_challenge_view.dart +++ b/lib/app/modules/alarmChallenge/views/qr_challenge_view.dart @@ -5,6 +5,7 @@ import 'package:get/get.dart'; import 'package:mobile_scanner/mobile_scanner.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; import '../controllers/alarm_challenge_controller.dart'; @@ -140,25 +141,10 @@ class QRChallengeView extends GetView { ), ), ), - TextButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty - .all( - kprimaryColor, - ), - ), - child: Text( - 'Retake'.tr, - style: Theme.of( - context, - ) - .textTheme - .displaySmall! - .copyWith( - color: themeController.secondaryTextColor.value, - ), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Retake'.tr, onPressed: () async { Utils.hapticFeedback(); controller.qrController! diff --git a/lib/app/modules/alarmRing/controllers/alarm_ring_controller.dart b/lib/app/modules/alarmRing/controllers/alarm_ring_controller.dart index cee4e80c..4fc280e5 100644 --- a/lib/app/modules/alarmRing/controllers/alarm_ring_controller.dart +++ b/lib/app/modules/alarmRing/controllers/alarm_ring_controller.dart @@ -19,7 +19,7 @@ import 'package:ultimate_alarm_clock/app/data/providers/secure_storage_provider. import 'package:ultimate_alarm_clock/app/modules/settings/controllers/settings_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; import 'package:ultimate_alarm_clock/app/utils/audio_utils.dart'; -import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; import 'package:vibration/vibration.dart'; @@ -211,21 +211,13 @@ class AlarmControlController extends GetxController { const SizedBox( height: 30, ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - kprimaryColor, - ), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Dismiss'.tr, onPressed: () { Get.back(); }, - child: Text( - 'Dismiss', - style: TextStyle( - color: themeController.secondaryTextColor.value, - ), - ), ), ], ), diff --git a/lib/app/modules/home/views/home_view.dart b/lib/app/modules/home/views/home_view.dart index d8f8b3ae..808322cc 100644 --- a/lib/app/modules/home/views/home_view.dart +++ b/lib/app/modules/home/views/home_view.dart @@ -14,6 +14,7 @@ import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_cont import 'package:ultimate_alarm_clock/app/utils/audio_utils.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; import 'package:ultimate_alarm_clock/app/utils/end_drawer.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; import '../controllers/home_controller.dart'; @@ -383,29 +384,17 @@ class HomeView extends GetView { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - TextButton( + UACTextButton( onPressed: () => Get.back(result: false), - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - kprimaryTextColor.withOpacity(0.5), - ), - ), - child: Text( - 'Cancel'.tr, - style: Theme.of(context).textTheme.displaySmall!, - ), + isButtonPrimary: false, + isTextPrimary: true, + text: 'Cancel'.tr, ), - TextButton( + UACTextButton( onPressed: () => Get.back(result: true), - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - 'Delete'.tr, - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: kprimaryBackgroundColor, - ), - ), + isButtonPrimary: true, + isTextPrimary: false, + text: 'Delete'.tr, ), ], ), @@ -1120,33 +1109,21 @@ class HomeView extends GetView { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - TextButton( + UACTextButton( onPressed: () { Get.back(result: false); }, - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - kprimaryTextColor.withOpacity(0.5), - ), - ), - child: Text( - 'Cancel'.tr, - style: Theme.of(context).textTheme.displaySmall!, - ), + isButtonPrimary: false, + isTextPrimary: true, + text: 'Cancel'.tr, ), - TextButton( + UACTextButton( onPressed: () { Get.back(result: true); // User confirmed }, - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(kprimaryColor), - ), - child: Text( - 'delete'.tr, - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: kprimaryBackgroundColor, - ), - ), + isButtonPrimary: true, + isTextPrimary: false, + text: 'Delete'.tr, ), ], ), diff --git a/lib/app/modules/settings/views/google_sign_in.dart b/lib/app/modules/settings/views/google_sign_in.dart index 38b14855..f8b542e0 100644 --- a/lib/app/modules/settings/views/google_sign_in.dart +++ b/lib/app/modules/settings/views/google_sign_in.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/settings_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; -import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import 'package:ultimate_alarm_clock/app/utils/utils.dart'; import '../../../data/providers/google_cloud_api_provider.dart'; @@ -54,18 +54,10 @@ class GoogleSignIn extends StatelessWidget { style: Theme.of(context).textTheme.displaySmall, ), ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(kprimaryColor), - ), - child: Obx( - () => Text( - 'Okay'.tr, - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: themeController.secondaryTextColor.value, - ), - ), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Okay'.tr, onPressed: () { Utils.hapticFeedback(); Get.back(); @@ -94,38 +86,20 @@ class GoogleSignIn extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - TextButton( - style: ButtonStyle( - backgroundColor: - MaterialStateProperty.all(kprimaryColor), - ), - child: Obx( - () => Text( - 'Unlink'.tr, - style: Theme.of(context) - .textTheme - .displaySmall! - .copyWith( - color: themeController.secondaryTextColor.value, - ), - ), - ), + UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Unlink'.tr, onPressed: () async { Utils.hapticFeedback(); await controller.logoutGoogle(); Get.back(); }, ), - TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - kprimaryTextColor.withOpacity(0.5), - ), - ), - child: Text( - 'Cancel'.tr, - style: Theme.of(context).textTheme.displaySmall!, - ), + UACTextButton( + isButtonPrimary: false, + isTextPrimary: true, + text: 'Cancel'.tr, onPressed: () { Utils.hapticFeedback(); Get.back(); @@ -250,26 +224,14 @@ class GoogleSignIn extends StatelessWidget { ), SizedBox( width: width, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - kprimaryColor, - ), - ), + child: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Understood'.tr, onPressed: () { Utils.hapticFeedback(); Get.back(); }, - child: Text( - 'Understood'.tr, - style: Theme.of(context) - .textTheme - .displaySmall! - .copyWith( - color: themeController - .secondaryTextColor.value, - ), - ), ), ), ], diff --git a/lib/app/modules/timerRing/views/timer_ring_view.dart b/lib/app/modules/timerRing/views/timer_ring_view.dart index f42b0d7d..9fc6a098 100644 --- a/lib/app/modules/timerRing/views/timer_ring_view.dart +++ b/lib/app/modules/timerRing/views/timer_ring_view.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; import 'package:ultimate_alarm_clock/app/modules/timerRing/controllers/timer_ring_controller.dart'; import 'package:ultimate_alarm_clock/app/utils/constants.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; class TimerRingView extends GetView { ThemeController themeController = Get.find(); @@ -35,23 +36,13 @@ class TimerRingView extends GetView { child: SizedBox( height: height * 0.06, width: width * 0.8, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - kprimaryColor, - ), - ), + child: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Stop'.tr, onPressed: () async { Get.offNamed('/bottom-navigation-bar'); }, - child: Obx( - () => Text( - 'Stop', - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: themeController.secondaryTextColor.value, - ), - ), - ), ), ), ), diff --git a/lib/app/utils/uac_text_button.dart b/lib/app/utils/uac_text_button.dart new file mode 100644 index 00000000..b7548f24 --- /dev/null +++ b/lib/app/utils/uac_text_button.dart @@ -0,0 +1,44 @@ +import 'package:flutter/material.dart'; +import 'package:get/get_core/src/get_main.dart'; +import 'package:get/get_instance/get_instance.dart'; +import 'package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart'; +import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart'; + +class UACTextButton extends StatelessWidget { + final bool isButtonPrimary; + final bool isTextPrimary; + final String text; + final VoidCallback onPressed; + + UACTextButton({ + super.key, + required this.isButtonPrimary, + required this.isTextPrimary, + required this.text, + required this.onPressed, + }); + + final ThemeController themeController = Get.find(); + + @override + Widget build(BuildContext context) { + return TextButton( + style: TextButton.styleFrom( + backgroundColor: isButtonPrimary + ? themeController.primaryColor.value + : themeController.primaryTextColor.value.withOpacity(0.5), + ), + onPressed: onPressed, + child: Obx( + () => Text( + text, + style: Theme.of(context).textTheme.displaySmall!.copyWith( + color: isTextPrimary + ? themeController.primaryTextColor.value + : themeController.secondaryTextColor.value, + ), + ), + ), + ); + } +} diff --git a/lib/app/utils/utils.dart b/lib/app/utils/utils.dart index 53c16127..882bba31 100644 --- a/lib/app/utils/utils.dart +++ b/lib/app/utils/utils.dart @@ -15,6 +15,7 @@ import 'package:ultimate_alarm_clock/app/data/models/quote_model.dart'; import 'package:ultimate_alarm_clock/app/data/models/timer_model.dart'; import 'package:ultimate_alarm_clock/app/data/providers/secure_storage_provider.dart'; import 'package:ultimate_alarm_clock/app/utils/quote_list.dart'; +import 'package:ultimate_alarm_clock/app/utils/uac_text_button.dart'; import '../data/models/profile_model.dart'; import '../data/providers/get_storage_provider.dart'; @@ -694,24 +695,14 @@ class Utils { ), SizedBox( width: MediaQuery.of(context).size.width, - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - kprimaryColor, - ), - ), + child: UACTextButton( + isButtonPrimary: true, + isTextPrimary: false, + text: 'Understood'.tr, onPressed: () { Utils.hapticFeedback(); Get.back(); }, - child: Text( - 'Understood'.tr, - style: Theme.of(context).textTheme.displaySmall!.copyWith( - color: isLightMode - ? kLightPrimaryTextColor - : ksecondaryTextColor, - ), - ), ), ), ],