diff --git a/lib/enums/meditation_reminder_options.dart b/lib/enums/meditation_reminder_options.dart new file mode 100644 index 0000000..b75e3de --- /dev/null +++ b/lib/enums/meditation_reminder_options.dart @@ -0,0 +1,5 @@ +enum MeditationReminderOptions { + yesAlreadyDone, + meditateNow, + later +} \ No newline at end of file diff --git a/lib/enums/taskoptions.dart b/lib/enums/taskoptions.dart index e93ab1f..5591388 100644 --- a/lib/enums/taskoptions.dart +++ b/lib/enums/taskoptions.dart @@ -1,2 +1,8 @@ // Enum to represent options in the menu -enum TaskOption { deleteAll,showKudos,launchMeditationScreen,exportToCSV,toggleMDR } +enum TaskOption { + deleteAll, + showKudos, + launchMeditationScreen, + exportToCSV, + toggleMDR, // to toggle Medatation Daily Reminder +} diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index 55599f4..218749b 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -33,8 +33,8 @@ class _HomeScreenState extends State { List tasks = []; Kudos kudos = Kudos(score: 0, history: []); Tip? tip; - bool MeditationDailyRemider = false; - String LastDateMeditationReminded = ""; + bool meditationDailyRemider = false; + String lastDateMeditationReminded = ""; @override void initState() { @@ -45,22 +45,18 @@ class _HomeScreenState extends State { _loadMeditationDailyReminderDetails(); } - void _loadMeditationDailyReminderDetails() async { - var _MeditationDailyRremider = await MeditationDailyRemiderStorage.get(); - var _LastDateMeditationReminded = await MeditationDailyRemiderStorage.getLastDate(); + void _loadMeditationDailyReminderDetails() async { + meditationDailyRemider = await MeditationDailyRemiderStorage.get(); + lastDateMeditationReminded = await MeditationDailyRemiderStorage.getLastDate(); setState(() { - MeditationDailyRemider = _MeditationDailyRremider; - LastDateMeditationReminded = _LastDateMeditationReminded; _checkMeditationReminder(); }); } void _checkMeditationReminder() async { - print(LastDateMeditationReminded); - print(MyDateUtils.getFormattedDate(DateTime.now())); - if (LastDateMeditationReminded != MyDateUtils.getFormattedDate(DateTime.now())) { + if (lastDateMeditationReminded == MyDateUtils.getFormattedDate(DateTime.now())) { await MeditationDailyRemiderStorage.saveLastDate(DateTime.now()); - if (MeditationDailyRemider) { + if (meditationDailyRemider) { // Show the notification showMeditationCheckDialog(context); } @@ -167,11 +163,11 @@ class _HomeScreenState extends State { exportToCSV(tasks); } else if (option == TaskOption.toggleMDR) { - if (MeditationDailyRemider) { - MeditationDailyRemider = false; + if (meditationDailyRemider) { + meditationDailyRemider = false; MeditationDailyRemiderStorage.save(false); } else { - MeditationDailyRemider = true; + meditationDailyRemider = true; MeditationDailyRemiderStorage.save(true); } } @@ -231,7 +227,6 @@ class _HomeScreenState extends State { final file = File(path); await file.writeAsString(csv); - print("File saved at: $path"); } void _loadKudos() async { @@ -288,7 +283,7 @@ class _HomeScreenState extends State { ), PopupMenuItem( value: TaskOption.toggleMDR, - child: MeditationDailyRemider + child: meditationDailyRemider ? const Text("Stop Daily Meditation Reminder") : const Text("Start Daily Meditation Reminder"), ) diff --git a/lib/storage/meditation_history_storage.dart b/lib/storage/meditation_history_storage.dart index d5f017c..8f5685c 100644 --- a/lib/storage/meditation_history_storage.dart +++ b/lib/storage/meditation_history_storage.dart @@ -58,28 +58,28 @@ class MeditationHistoryStorage { class MeditationDailyRemiderStorage { - static const String _MDRSKey = 'MDRS'; - static const String _MDRSDateKey = 'MDRSDATE'; + static const String _mdrsKey = 'MDRS'; // MDRS = Meditation Daily Reminder Storage + static const String _mdrsDateKey = 'MDRSDATE'; // MDRSDATE = Meditation Daily Reminder Storage Date static Future save(bool remind) async { final prefs = await SharedPreferences.getInstance(); - await prefs.setString(_MDRSKey, remind.toString()); + await prefs.setString(_mdrsKey, remind.toString()); } static Future get() async { final prefs = await SharedPreferences.getInstance(); - String? data = prefs.getString(_MDRSKey); + String? data = prefs.getString(_mdrsKey); return data == 'true'; } static Future saveLastDate(DateTime date) async { final prefs = await SharedPreferences.getInstance(); - await prefs.setString(_MDRSDateKey, MyDateUtils.getFormattedDate(date)); + await prefs.setString(_mdrsDateKey, MyDateUtils.getFormattedDate(date)); } static Future getLastDate() async { final prefs = await SharedPreferences.getInstance(); - String date = prefs.getString(_MDRSDateKey) ?? MyDateUtils.getFormattedDate(DateTime.now().subtract(const Duration(days: 1))); + String date = prefs.getString(_mdrsDateKey) ?? MyDateUtils.getFormattedDate(DateTime.now().subtract(const Duration(days: 1))); return date; } } diff --git a/lib/widgets/meditation_reminder_widget.dart b/lib/widgets/meditation_reminder_widget.dart index d37301f..52a6087 100644 --- a/lib/widgets/meditation_reminder_widget.dart +++ b/lib/widgets/meditation_reminder_widget.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:taskly/enums/meditation_reminder_options.dart'; import 'package:taskly/screens/meditation_screen.dart'; class MeditationCheckDialog extends StatelessWidget { @@ -72,7 +73,7 @@ class MeditationCheckDialog extends StatelessWidget { Column( children: [ ElevatedButton( - onPressed: () => Navigator.of(context).pop('yes'), + onPressed: () => Navigator.of(context).pop(MeditationReminderOptions.yesAlreadyDone), style: ElevatedButton.styleFrom( backgroundColor: Colors.green, minimumSize: const Size(double.infinity, 48), @@ -81,14 +82,14 @@ class MeditationCheckDialog extends StatelessWidget { ), ), child: const Text( - 'Yes', + 'Yes Already Done 👍', style: TextStyle(fontSize: 16, color: Colors.white), ), ), const SizedBox(height: 12), ElevatedButton( - onPressed: () => Navigator.of(context).pop('meditate_now'), + onPressed: () => Navigator.of(context).pop(MeditationReminderOptions.meditateNow), style: ElevatedButton.styleFrom( backgroundColor: Colors.blue, minimumSize: const Size(double.infinity, 48), @@ -97,14 +98,14 @@ class MeditationCheckDialog extends StatelessWidget { ), ), child: const Text( - 'Meditate Now', + 'Meditate Now 🧘‍♂️', style: TextStyle(fontSize: 16, color: Colors.white), ), ), const SizedBox(height: 12), TextButton( - onPressed: () => Navigator.of(context).pop('later'), + onPressed: () => Navigator.of(context).pop(MeditationReminderOptions.later), style: TextButton.styleFrom( minimumSize: const Size(double.infinity, 48), shape: RoundedRectangleBorder( @@ -185,26 +186,22 @@ void showMeditationCheckDialog(BuildContext context) { context: context, builder: (context) => const MeditationCheckDialog(), ).then((value) { - switch (value) { - case 'yes': - const MeditationCheckDialog()._showSimpleCelebration(context); - break; - - case 'meditate_now': - Navigator.push( + if (value == MeditationReminderOptions.yesAlreadyDone){ + const MeditationCheckDialog()._showSimpleCelebration(context); + } + else if (value == MeditationReminderOptions.meditateNow){ + Navigator.push( context, MaterialPageRoute(builder: (context) => const MeditationScreen()), ); - break; - - case 'later': - ScaffoldMessenger.of(context).showSnackBar( + } + else if (value== MeditationReminderOptions.later){ + ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text("Don't forget to take a moment for yourself today"), duration: Duration(seconds: 2), ), ); - break; } }); -} \ No newline at end of file +}