Skip to content

Commit df591b8

Browse files
Fixed 24 hour app settings to reflect all over app
1 parent 7eaf8fd commit df591b8

20 files changed

+295
-107
lines changed

lib/app/modules/detailRoute/views/dateTimePicker.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ class DateTimeWidget extends StatelessWidget {
155155
var time = await showTimePicker(
156156
context: context,
157157
initialTime: TimeOfDay.now(),
158+
builder: (BuildContext context, Widget? child) {
159+
return MediaQuery(
160+
data: MediaQuery.of(context).copyWith(
161+
alwaysUse24HourFormat: AppSettings.use24HourFormatRx.value,
162+
),
163+
child: child!,
164+
);
165+
},
158166
);
159167
if (time != null) {
160168
var dateTime = date.add(

lib/app/modules/detailRoute/views/detail_route_view.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ class AttributeWidget extends StatelessWidget {
249249
@override
250250
Widget build(BuildContext context) {
251251
var localValue = (value is DateTime)
252-
? DateFormat.yMEd().add_jms().format(value.toLocal())
252+
? DateFormat(AppSettings.use24HourFormatRx.value
253+
? 'EEE, yyyy-MM-dd HH:mm:ss'
254+
: 'EEE, yyyy-MM-dd hh:mm:ss a')
255+
.format(value.toLocal())
253256
: ((value is BuiltList) ? (value).toBuilder() : value);
254257

255258
switch (name) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ class HomeController extends GetxController {
7979
handleHomeWidgetClicked();
8080
}
8181
fetchTasksFromDB();
82+
83+
ever(AppSettings.use24HourFormatRx, (_) {
84+
_refreshTasks();
85+
update();
86+
});
87+
8288
everAll([
8389
pendingFilter,
8490
waitingFilter,
@@ -499,7 +505,6 @@ class HomeController extends GetxController {
499505
RxBool syncOnStart = false.obs;
500506
RxBool syncOnTaskCreate = false.obs;
501507
RxBool delaytask = false.obs;
502-
RxBool change24hr = false.obs;
503508
RxBool taskchampion = false.obs;
504509

505510
// dialogue box

lib/app/modules/home/views/add_task_bottom_sheet.dart

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class AddTaskBottomSheet extends StatelessWidget {
250250
},
251251
fieldHintText: "Month/Date/Year",
252252
context: context,
253-
initialDate: homeController.due.value?? DateTime.now(),
253+
initialDate: homeController.due.value ?? DateTime.now(),
254254
firstDate: DateTime.now(),
255255
lastDate: DateTime(2037, 12, 31),
256256
);
@@ -287,7 +287,7 @@ class AddTaskBottomSheet extends StatelessWidget {
287287
child: Obx(() => MediaQuery(
288288
data: MediaQuery.of(context).copyWith(
289289
alwaysUse24HourFormat:
290-
homeController.change24hr.value,
290+
AppSettings.use24HourFormatRx.value,
291291
),
292292
child: child!)),
293293
);
@@ -308,8 +308,11 @@ class AddTaskBottomSheet extends StatelessWidget {
308308
homeController.due.value = dateTime;
309309

310310
// print("due value ${homeController.due}");
311+
String timeFormat = AppSettings.use24HourFormatRx.value
312+
? 'dd-MM-yyyy HH:mm'
313+
: 'dd-MM-yyyy hh:mm a';
311314
homeController.dueString.value =
312-
DateFormat("dd-MM-yyyy HH:mm").format(dateTime);
315+
DateFormat(timeFormat).format(dateTime);
313316
// print(homeController.dueString.value);
314317
if (dateTime.isBefore(DateTime.now())) {
315318
//Try changing the color. in the settings and Due display.
@@ -355,10 +358,7 @@ class AddTaskBottomSheet extends StatelessWidget {
355358
crossAxisAlignment: CrossAxisAlignment.center,
356359
children: [
357360
Text(
358-
"${SentenceManager(
359-
currentLanguage: homeController.selectedLanguage.value)
360-
.sentences
361-
.addTaskPriority} :",
361+
"${SentenceManager(currentLanguage: homeController.selectedLanguage.value).sentences.addTaskPriority} :",
362362
style: GoogleFonts.poppins(
363363
fontWeight: TaskWarriorFonts.bold,
364364
color: AppSettings.isDarkMode
@@ -367,51 +367,54 @@ class AddTaskBottomSheet extends StatelessWidget {
367367
),
368368
textAlign: TextAlign.left,
369369
),
370-
const SizedBox(width: 2,),
370+
const SizedBox(
371+
width: 2,
372+
),
371373
Obx(
372374
() => Row(
373375
children: [
374-
for(int i=0;i<homeController.priorityList.length;i++)
376+
for (int i = 0; i < homeController.priorityList.length; i++)
375377
Padding(
376378
padding: const EdgeInsets.symmetric(horizontal: 2.5),
377379
child: GestureDetector(
378380
onTap: () {
379-
homeController.priority.value = homeController.priorityList[i];
381+
homeController.priority.value =
382+
homeController.priorityList[i];
380383
debugPrint(homeController.priority.value);
381384
},
382385
child: AnimatedContainer(
383386
duration: const Duration(milliseconds: 100),
384387
height: 30,
385388
width: 37,
386389
decoration: BoxDecoration(
387-
388-
borderRadius: BorderRadius.circular(8),
389-
border: Border.all(
390-
color: homeController.priority.value == homeController.priorityList[i]
391-
? AppSettings.isDarkMode
392-
? TaskWarriorColors.kLightPrimaryBackgroundColor
393-
: TaskWarriorColors.kprimaryBackgroundColor
394-
: AppSettings.isDarkMode
395-
? TaskWarriorColors.kprimaryBackgroundColor
396-
: TaskWarriorColors.kLightPrimaryBackgroundColor,
397-
)
398-
),
390+
borderRadius: BorderRadius.circular(8),
391+
border: Border.all(
392+
color: homeController.priority.value ==
393+
homeController.priorityList[i]
394+
? AppSettings.isDarkMode
395+
? TaskWarriorColors
396+
.kLightPrimaryBackgroundColor
397+
: TaskWarriorColors
398+
.kprimaryBackgroundColor
399+
: AppSettings.isDarkMode
400+
? TaskWarriorColors
401+
.kprimaryBackgroundColor
402+
: TaskWarriorColors
403+
.kLightPrimaryBackgroundColor,
404+
)),
399405
child: Center(
400406
child: Text(
401407
homeController.priorityList[i],
402408
textAlign: TextAlign.center,
403409
style: GoogleFonts.poppins(
404-
fontWeight: FontWeight.bold,
405-
fontSize: 17,
406-
color: homeController.priorityColors[i]
407-
),
410+
fontWeight: FontWeight.bold,
411+
fontSize: 17,
412+
color: homeController.priorityColors[i]),
408413
),
409414
),
410415
),
411-
412416
),
413417
)
414-
415418
],
416419
),
417420
)
@@ -448,8 +451,7 @@ class AddTaskBottomSheet extends StatelessWidget {
448451
Widget buildAddButton(BuildContext context) {
449452
return TextButton(
450453
child: Text(
451-
SentenceManager(
452-
currentLanguage: homeController.selectedLanguage.value)
454+
SentenceManager(currentLanguage: homeController.selectedLanguage.value)
453455
.sentences
454456
.addTaskAdd,
455457
style: TextStyle(
@@ -460,12 +462,12 @@ class AddTaskBottomSheet extends StatelessWidget {
460462
),
461463
onPressed: () async {
462464
// print(homeController.formKey.currentState);
463-
if(homeController.due.value!=null&&DateTime.now().isAfter(homeController.due.value!)){
465+
if (homeController.due.value != null &&
466+
DateTime.now().isAfter(homeController.due.value!)) {
464467
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
465468
content: Text(
466469
SentenceManager(
467-
currentLanguage:
468-
homeController.selectedLanguage.value)
470+
currentLanguage: homeController.selectedLanguage.value)
469471
.sentences
470472
.addTaskTimeInPast,
471473
style: TextStyle(
@@ -476,8 +478,7 @@ class AddTaskBottomSheet extends StatelessWidget {
476478
),
477479
backgroundColor: AppSettings.isDarkMode
478480
? TaskWarriorColors.ksecondaryBackgroundColor
479-
: TaskWarriorColors
480-
.kLightSecondaryBackgroundColor,
481+
: TaskWarriorColors.kLightSecondaryBackgroundColor,
481482
duration: const Duration(seconds: 2)));
482483
return;
483484
}
@@ -501,13 +502,12 @@ class AddTaskBottomSheet extends StatelessWidget {
501502
homeController.priority.value = 'M';
502503
homeController.tagcontroller.text = '';
503504
homeController.tags.value = [];
504-
homeController.due.value=null;
505+
homeController.due.value = null;
505506
homeController.update();
506507
// Navigator.of(context).pop();
507508
Get.back();
508509
if (Platform.isAndroid) {
509-
WidgetController widgetController =
510-
Get.put(WidgetController());
510+
WidgetController widgetController = Get.put(WidgetController());
511511
widgetController.fetchAllData();
512512

513513
widgetController.update();
@@ -518,7 +518,8 @@ class AddTaskBottomSheet extends StatelessWidget {
518518
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
519519
content: Text(
520520
SentenceManager(
521-
currentLanguage: homeController.selectedLanguage.value)
521+
currentLanguage:
522+
homeController.selectedLanguage.value)
522523
.sentences
523524
.addTaskTaskAddedSuccessfully,
524525
style: TextStyle(
@@ -567,18 +568,20 @@ class AddTaskBottomSheet extends StatelessWidget {
567568
if (tag.isNotEmpty) {
568569
String trimmedString = tag.trim();
569570
List<String> tags = trimmedString.split(" ");
570-
for(tag in tags){
571-
if(checkTagIfExists(tag)) {
571+
for (tag in tags) {
572+
if (checkTagIfExists(tag)) {
572573
removeTag(tag);
573574
}
574575
homeController.tags.add(tag);
575576
}
576577
homeController.tagcontroller.text = '';
577578
}
578579
}
579-
bool checkTagIfExists(String tag){
580+
581+
bool checkTagIfExists(String tag) {
580582
return homeController.tags.contains(tag);
581583
}
584+
582585
void removeTag(String tag) {
583586
homeController.tags.remove(tag);
584587
}

lib/app/modules/home/views/add_task_to_taskc_bottom_sheet.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class AddTaskToTaskcBottomSheet extends StatelessWidget {
217217
child: MediaQuery(
218218
data: MediaQuery.of(context).copyWith(
219219
alwaysUse24HourFormat:
220-
homeController.change24hr.value,
220+
AppSettings.use24HourFormatRx.value,
221221
),
222222
child: child!),
223223
);
@@ -234,8 +234,11 @@ class AddTaskToTaskcBottomSheet extends StatelessWidget {
234234
),
235235
);
236236
homeController.due.value = dateTime.toUtc();
237+
String timeFormat = AppSettings.use24HourFormatRx.value
238+
? 'yyyy-MM-dd HH:mm'
239+
: 'yyyy-MM-dd hh:mm a';
237240
homeController.dueString.value =
238-
DateFormat("yyyy-MM-dd").format(dateTime);
241+
DateFormat(timeFormat).format(dateTime);
239242
if (dateTime.isBefore(DateTime.now())) {
240243
homeController.inThePast.value = true;
241244

lib/app/modules/home/views/nav_drawer.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ class NavDrawer extends StatelessWidget {
238238
prefs.getBool('sync-OnTaskCreate') ?? false;
239239
homeController.delaytask.value =
240240
prefs.getBool('delaytask') ?? false;
241-
homeController.change24hr.value =
242-
prefs.getBool('24hourformate') ?? false;
243241

244242
Get.toNamed(Routes.SETTINGS);
245243
},

lib/app/modules/home/views/show_details.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,10 @@ class _TaskDetailsState extends State<TaskDetails> {
360360

361361
try {
362362
DateTime parsedDate = DateTime.parse(dateString);
363-
return DateFormat('yyyy-MM-dd HH:mm:ss').format(parsedDate);
363+
String timeFormat = AppSettings.use24HourFormatRx.value
364+
? 'yyyy-MM-dd HH:mm:ss'
365+
: 'yyyy-MM-dd hh:mm:ss a';
366+
return DateFormat(timeFormat).format(parsedDate);
364367
} catch (e) {
365368
debugPrint('Error parsing date: $dateString');
366369
return '-';

lib/app/modules/settings/controllers/settings_controller.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ class SettingsController extends GetxController {
165165
RxBool isSyncOnStartActivel = false.obs;
166166
RxBool isSyncOnTaskCreateActivel = false.obs;
167167
RxBool delaytask = false.obs;
168-
RxBool change24hr = false.obs;
169168
RxBool taskchampion = false.obs;
170169
RxBool isDarkModeOn = false.obs;
171170

@@ -180,7 +179,6 @@ class SettingsController extends GetxController {
180179
isSyncOnTaskCreateActivel.value =
181180
prefs.getBool('sync-OnTaskCreate') ?? false;
182181
delaytask.value = prefs.getBool('delaytask') ?? false;
183-
change24hr.value = prefs.getBool('24hourformate') ?? false;
184182
taskchampion.value = prefs.getBool('taskc') ?? false;
185183
initDarkMode();
186184
baseDirectory.value = await getBaseDirectory();

lib/app/modules/settings/views/settings_page_enable_24hr_format_list_tile_trailing.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import 'package:flutter/material.dart';
22

33
import 'package:get/get.dart';
4-
import 'package:shared_preferences/shared_preferences.dart';
5-
import 'package:taskwarrior/app/modules/home/controllers/home_controller.dart';
4+
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';
65

76
import '../controllers/settings_controller.dart';
87

9-
108
class SettingsPageEnable24hrFormatListTileTrailing extends StatelessWidget {
119
final SettingsController controller;
1210
const SettingsPageEnable24hrFormatListTileTrailing(
@@ -16,13 +14,14 @@ class SettingsPageEnable24hrFormatListTileTrailing extends StatelessWidget {
1614
Widget build(BuildContext context) {
1715
return Obx(
1816
() => Switch(
19-
value: controller.change24hr.value,
17+
value: AppSettings.use24HourFormatRx.value,
2018
onChanged: (bool value) async {
21-
controller.change24hr.value = value;
22-
23-
final SharedPreferences prefs = await SharedPreferences.getInstance();
24-
await prefs.setBool('24hourformate', value);
25-
Get.find<HomeController>().change24hr.value = value;
19+
AppSettings.use24HourFormatRx.value = value;
20+
AppSettings.saveSettings(
21+
AppSettings.isDarkMode,
22+
AppSettings.selectedLanguage,
23+
value,
24+
);
2625
},
2726
),
2827
);

lib/app/services/notification_services.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'package:flutter/foundation.dart';
77
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
88
import 'package:timezone/data/latest.dart' as tz;
99
import 'package:timezone/timezone.dart' as tz;
10+
import 'package:intl/intl.dart';
11+
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';
1012

1113
class NotificationService {
1214
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
@@ -53,13 +55,21 @@ class NotificationService {
5355
return notificationId;
5456
}
5557

58+
// Helper method to format date time based on user preferences
59+
String getFormattedDateTime(DateTime dateTime) {
60+
String timeFormat = AppSettings.use24HourFormatRx.value
61+
? 'yyyy-MM-dd HH:mm:ss'
62+
: 'yyyy-MM-dd hh:mm:ss a';
63+
return DateFormat(timeFormat).format(dateTime);
64+
}
65+
5666
void sendNotification(
5767
DateTime dtb, String taskname, bool isWait, DateTime entryTime) async {
5868
DateTime dateTime = DateTime.now();
5969
tz.initializeTimeZones();
6070
if (kDebugMode) {
6171
print("date and time are:-$dateTime");
62-
print("date and time are:-$dtb");
72+
print("date and time are:-${getFormattedDateTime(dtb)}");
6373
}
6474
final tz.TZDateTime scheduledAt =
6575
tz.TZDateTime.from(dtb.add(const Duration(minutes: 0)), tz.local);

0 commit comments

Comments
 (0)