Skip to content

fix: fixed 24 hour app settings to reflect all over app #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/app/modules/detailRoute/views/dateTimePicker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ class DateTimeWidget extends StatelessWidget {
var time = await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
builder: (BuildContext context, Widget? child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
alwaysUse24HourFormat: AppSettings.use24HourFormatRx.value,
),
child: child!,
);
},
);
if (time != null) {
var dateTime = date.add(
Expand Down
5 changes: 4 additions & 1 deletion lib/app/modules/detailRoute/views/detail_route_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ class AttributeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
var localValue = (value is DateTime)
? DateFormat.yMEd().add_jms().format(value.toLocal())
? DateFormat(AppSettings.use24HourFormatRx.value
? 'EEE, yyyy-MM-dd HH:mm:ss'
: 'EEE, yyyy-MM-dd hh:mm:ss a')
.format(value.toLocal())
: ((value is BuiltList) ? (value).toBuilder() : value);

switch (name) {
Expand Down
7 changes: 6 additions & 1 deletion lib/app/modules/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class HomeController extends GetxController {
handleHomeWidgetClicked();
}
fetchTasksFromDB();

ever(AppSettings.use24HourFormatRx, (_) {
_refreshTasks();
update();
});

everAll([
pendingFilter,
waitingFilter,
Expand Down Expand Up @@ -499,7 +505,6 @@ class HomeController extends GetxController {
RxBool syncOnStart = false.obs;
RxBool syncOnTaskCreate = false.obs;
RxBool delaytask = false.obs;
RxBool change24hr = false.obs;
RxBool taskchampion = false.obs;

// dialogue box
Expand Down
87 changes: 45 additions & 42 deletions lib/app/modules/home/views/add_task_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class AddTaskBottomSheet extends StatelessWidget {
},
fieldHintText: "Month/Date/Year",
context: context,
initialDate: homeController.due.value?? DateTime.now(),
initialDate: homeController.due.value ?? DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime(2037, 12, 31),
);
Expand Down Expand Up @@ -287,7 +287,7 @@ class AddTaskBottomSheet extends StatelessWidget {
child: Obx(() => MediaQuery(
data: MediaQuery.of(context).copyWith(
alwaysUse24HourFormat:
homeController.change24hr.value,
AppSettings.use24HourFormatRx.value,
),
child: child!)),
);
Expand All @@ -308,8 +308,11 @@ class AddTaskBottomSheet extends StatelessWidget {
homeController.due.value = dateTime;

// print("due value ${homeController.due}");
String timeFormat = AppSettings.use24HourFormatRx.value
? 'dd-MM-yyyy HH:mm'
: 'dd-MM-yyyy hh:mm a';
homeController.dueString.value =
DateFormat("dd-MM-yyyy HH:mm").format(dateTime);
DateFormat(timeFormat).format(dateTime);
// print(homeController.dueString.value);
if (dateTime.isBefore(DateTime.now())) {
//Try changing the color. in the settings and Due display.
Expand Down Expand Up @@ -355,10 +358,7 @@ class AddTaskBottomSheet extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"${SentenceManager(
currentLanguage: homeController.selectedLanguage.value)
.sentences
.addTaskPriority} :",
"${SentenceManager(currentLanguage: homeController.selectedLanguage.value).sentences.addTaskPriority} :",
style: GoogleFonts.poppins(
fontWeight: TaskWarriorFonts.bold,
color: AppSettings.isDarkMode
Expand All @@ -367,51 +367,54 @@ class AddTaskBottomSheet extends StatelessWidget {
),
textAlign: TextAlign.left,
),
const SizedBox(width: 2,),
const SizedBox(
width: 2,
),
Obx(
() => Row(
children: [
for(int i=0;i<homeController.priorityList.length;i++)
for (int i = 0; i < homeController.priorityList.length; i++)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.5),
child: GestureDetector(
onTap: () {
homeController.priority.value = homeController.priorityList[i];
homeController.priority.value =
homeController.priorityList[i];
debugPrint(homeController.priority.value);
},
child: AnimatedContainer(
duration: const Duration(milliseconds: 100),
height: 30,
width: 37,
decoration: BoxDecoration(

borderRadius: BorderRadius.circular(8),
border: Border.all(
color: homeController.priority.value == homeController.priorityList[i]
? AppSettings.isDarkMode
? TaskWarriorColors.kLightPrimaryBackgroundColor
: TaskWarriorColors.kprimaryBackgroundColor
: AppSettings.isDarkMode
? TaskWarriorColors.kprimaryBackgroundColor
: TaskWarriorColors.kLightPrimaryBackgroundColor,
)
),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: homeController.priority.value ==
homeController.priorityList[i]
? AppSettings.isDarkMode
? TaskWarriorColors
.kLightPrimaryBackgroundColor
: TaskWarriorColors
.kprimaryBackgroundColor
: AppSettings.isDarkMode
? TaskWarriorColors
.kprimaryBackgroundColor
: TaskWarriorColors
.kLightPrimaryBackgroundColor,
)),
child: Center(
child: Text(
homeController.priorityList[i],
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
fontWeight: FontWeight.bold,
fontSize: 17,
color: homeController.priorityColors[i]
),
fontWeight: FontWeight.bold,
fontSize: 17,
color: homeController.priorityColors[i]),
),
),
),

),
)

],
),
)
Expand Down Expand Up @@ -448,8 +451,7 @@ class AddTaskBottomSheet extends StatelessWidget {
Widget buildAddButton(BuildContext context) {
return TextButton(
child: Text(
SentenceManager(
currentLanguage: homeController.selectedLanguage.value)
SentenceManager(currentLanguage: homeController.selectedLanguage.value)
.sentences
.addTaskAdd,
style: TextStyle(
Expand All @@ -460,12 +462,12 @@ class AddTaskBottomSheet extends StatelessWidget {
),
onPressed: () async {
// print(homeController.formKey.currentState);
if(homeController.due.value!=null&&DateTime.now().isAfter(homeController.due.value!)){
if (homeController.due.value != null &&
DateTime.now().isAfter(homeController.due.value!)) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
SentenceManager(
currentLanguage:
homeController.selectedLanguage.value)
currentLanguage: homeController.selectedLanguage.value)
.sentences
.addTaskTimeInPast,
style: TextStyle(
Expand All @@ -476,8 +478,7 @@ class AddTaskBottomSheet extends StatelessWidget {
),
backgroundColor: AppSettings.isDarkMode
? TaskWarriorColors.ksecondaryBackgroundColor
: TaskWarriorColors
.kLightSecondaryBackgroundColor,
: TaskWarriorColors.kLightSecondaryBackgroundColor,
duration: const Duration(seconds: 2)));
return;
}
Expand All @@ -501,13 +502,12 @@ class AddTaskBottomSheet extends StatelessWidget {
homeController.priority.value = 'M';
homeController.tagcontroller.text = '';
homeController.tags.value = [];
homeController.due.value=null;
homeController.due.value = null;
homeController.update();
// Navigator.of(context).pop();
Get.back();
if (Platform.isAndroid) {
WidgetController widgetController =
Get.put(WidgetController());
WidgetController widgetController = Get.put(WidgetController());
widgetController.fetchAllData();

widgetController.update();
Expand All @@ -518,7 +518,8 @@ class AddTaskBottomSheet extends StatelessWidget {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
SentenceManager(
currentLanguage: homeController.selectedLanguage.value)
currentLanguage:
homeController.selectedLanguage.value)
.sentences
.addTaskTaskAddedSuccessfully,
style: TextStyle(
Expand Down Expand Up @@ -567,18 +568,20 @@ class AddTaskBottomSheet extends StatelessWidget {
if (tag.isNotEmpty) {
String trimmedString = tag.trim();
List<String> tags = trimmedString.split(" ");
for(tag in tags){
if(checkTagIfExists(tag)) {
for (tag in tags) {
if (checkTagIfExists(tag)) {
removeTag(tag);
}
homeController.tags.add(tag);
}
homeController.tagcontroller.text = '';
}
}
bool checkTagIfExists(String tag){

bool checkTagIfExists(String tag) {
return homeController.tags.contains(tag);
}

void removeTag(String tag) {
homeController.tags.remove(tag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class AddTaskToTaskcBottomSheet extends StatelessWidget {
child: MediaQuery(
data: MediaQuery.of(context).copyWith(
alwaysUse24HourFormat:
homeController.change24hr.value,
AppSettings.use24HourFormatRx.value,
),
child: child!),
);
Expand All @@ -234,8 +234,11 @@ class AddTaskToTaskcBottomSheet extends StatelessWidget {
),
);
homeController.due.value = dateTime.toUtc();
String timeFormat = AppSettings.use24HourFormatRx.value
? 'yyyy-MM-dd HH:mm'
: 'yyyy-MM-dd hh:mm a';
homeController.dueString.value =
DateFormat("yyyy-MM-dd").format(dateTime);
DateFormat(timeFormat).format(dateTime);
if (dateTime.isBefore(DateTime.now())) {
homeController.inThePast.value = true;

Expand Down
2 changes: 0 additions & 2 deletions lib/app/modules/home/views/nav_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ class NavDrawer extends StatelessWidget {
prefs.getBool('sync-OnTaskCreate') ?? false;
homeController.delaytask.value =
prefs.getBool('delaytask') ?? false;
homeController.change24hr.value =
prefs.getBool('24hourformate') ?? false;

Get.toNamed(Routes.SETTINGS);
},
Expand Down
5 changes: 4 additions & 1 deletion lib/app/modules/home/views/show_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ class _TaskDetailsState extends State<TaskDetails> {

try {
DateTime parsedDate = DateTime.parse(dateString);
return DateFormat('yyyy-MM-dd HH:mm:ss').format(parsedDate);
String timeFormat = AppSettings.use24HourFormatRx.value
? 'yyyy-MM-dd HH:mm:ss'
: 'yyyy-MM-dd hh:mm:ss a';
return DateFormat(timeFormat).format(parsedDate);
} catch (e) {
debugPrint('Error parsing date: $dateString');
return '-';
Expand Down
2 changes: 0 additions & 2 deletions lib/app/modules/settings/controllers/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ class SettingsController extends GetxController {
RxBool isSyncOnStartActivel = false.obs;
RxBool isSyncOnTaskCreateActivel = false.obs;
RxBool delaytask = false.obs;
RxBool change24hr = false.obs;
RxBool taskchampion = false.obs;
RxBool isDarkModeOn = false.obs;

Expand All @@ -180,7 +179,6 @@ class SettingsController extends GetxController {
isSyncOnTaskCreateActivel.value =
prefs.getBool('sync-OnTaskCreate') ?? false;
delaytask.value = prefs.getBool('delaytask') ?? false;
change24hr.value = prefs.getBool('24hourformate') ?? false;
taskchampion.value = prefs.getBool('taskc') ?? false;
initDarkMode();
baseDirectory.value = await getBaseDirectory();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:taskwarrior/app/modules/home/controllers/home_controller.dart';
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';

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


class SettingsPageEnable24hrFormatListTileTrailing extends StatelessWidget {
final SettingsController controller;
const SettingsPageEnable24hrFormatListTileTrailing(
Expand All @@ -16,13 +14,14 @@ class SettingsPageEnable24hrFormatListTileTrailing extends StatelessWidget {
Widget build(BuildContext context) {
return Obx(
() => Switch(
value: controller.change24hr.value,
value: AppSettings.use24HourFormatRx.value,
onChanged: (bool value) async {
controller.change24hr.value = value;

final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setBool('24hourformate', value);
Get.find<HomeController>().change24hr.value = value;
AppSettings.use24HourFormatRx.value = value;
AppSettings.saveSettings(
AppSettings.isDarkMode,
AppSettings.selectedLanguage,
value,
);
},
),
);
Expand Down
12 changes: 11 additions & 1 deletion lib/app/services/notification_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:flutter/foundation.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:timezone/data/latest.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import 'package:intl/intl.dart';
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';

class NotificationService {
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
Expand Down Expand Up @@ -53,13 +55,21 @@ class NotificationService {
return notificationId;
}

// Helper method to format date time based on user preferences
String getFormattedDateTime(DateTime dateTime) {
String timeFormat = AppSettings.use24HourFormatRx.value
? 'yyyy-MM-dd HH:mm:ss'
: 'yyyy-MM-dd hh:mm:ss a';
return DateFormat(timeFormat).format(dateTime);
}

void sendNotification(
DateTime dtb, String taskname, bool isWait, DateTime entryTime) async {
DateTime dateTime = DateTime.now();
tz.initializeTimeZones();
if (kDebugMode) {
print("date and time are:-$dateTime");
print("date and time are:-$dtb");
print("date and time are:-${getFormattedDateTime(dtb)}");
}
final tz.TZDateTime scheduledAt =
tz.TZDateTime.from(dtb.add(const Duration(minutes: 0)), tz.local);
Expand Down
Loading
Loading