Skip to content

Commit

Permalink
applied all asked fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanat-Jha committed Jan 8, 2025
1 parent 98f9da5 commit 6a77e55
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
5 changes: 5 additions & 0 deletions lib/enums/meditation_reminder_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum MeditationReminderOptions {
yesAlreadyDone,
meditateNow,
later
}
8 changes: 7 additions & 1 deletion lib/enums/taskoptions.dart
Original file line number Diff line number Diff line change
@@ -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
}
27 changes: 11 additions & 16 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class _HomeScreenState extends State<HomeScreen> {
List<Task> tasks = [];
Kudos kudos = Kudos(score: 0, history: []);
Tip? tip;
bool MeditationDailyRemider = false;
String LastDateMeditationReminded = "";
bool meditationDailyRemider = false;
String lastDateMeditationReminded = "";

@override
void initState() {
Expand All @@ -45,22 +45,18 @@ class _HomeScreenState extends State<HomeScreen> {
_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);
}
Expand Down Expand Up @@ -167,11 +163,11 @@ class _HomeScreenState extends State<HomeScreen> {
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);
}
}
Expand Down Expand Up @@ -231,7 +227,6 @@ class _HomeScreenState extends State<HomeScreen> {
final file = File(path);
await file.writeAsString(csv);

print("File saved at: $path");
}

void _loadKudos() async {
Expand Down Expand Up @@ -288,7 +283,7 @@ class _HomeScreenState extends State<HomeScreen> {
),
PopupMenuItem(
value: TaskOption.toggleMDR,
child: MeditationDailyRemider
child: meditationDailyRemider
? const Text("Stop Daily Meditation Reminder")
: const Text("Start Daily Meditation Reminder"),
)
Expand Down
12 changes: 6 additions & 6 deletions lib/storage/meditation_history_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> save(bool remind) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_MDRSKey, remind.toString());
await prefs.setString(_mdrsKey, remind.toString());
}

static Future<bool> get() async {
final prefs = await SharedPreferences.getInstance();
String? data = prefs.getString(_MDRSKey);
String? data = prefs.getString(_mdrsKey);
return data == 'true';
}

static Future<void> 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<String> 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;
}
}
33 changes: 15 additions & 18 deletions lib/widgets/meditation_reminder_widget.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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(
Expand Down Expand Up @@ -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;
}
});
}
}

0 comments on commit 6a77e55

Please sign in to comment.