From 732efff7387eb34adc2446b7a8825e22bb9ed4df Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Thu, 1 Feb 2024 19:22:49 +0530 Subject: [PATCH 1/4] Make time after there --- lib/widgets/add_Task.dart | 418 +++++++++++++++++++------------------- 1 file changed, 213 insertions(+), 205 deletions(-) diff --git a/lib/widgets/add_Task.dart b/lib/widgets/add_Task.dart index 05a1a4e3..2960ef02 100644 --- a/lib/widgets/add_Task.dart +++ b/lib/widgets/add_Task.dart @@ -1,5 +1,3 @@ -// ignore_for_file: library_private_types_in_public_api, use_build_context_synchronously, file_names - import 'dart:developer'; import 'package:flutter/material.dart'; @@ -118,12 +116,11 @@ class _AddTaskBottomSheetState extends State { }, ), ), - // Replace ElevatedButton with IconButton IconButton( onPressed: () { addTag(tagcontroller.text.trim()); }, - icon: const Icon(Icons.add), // Plus icon + icon: const Icon(Icons.add), ), ], ), @@ -143,223 +140,234 @@ class _AddTaskBottomSheetState extends State { } Widget buildName() => TextFormField( - autofocus: true, - controller: namecontroller, - style: TextStyle( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - decoration: InputDecoration( - hintText: 'Enter Task', - hintStyle: TextStyle( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - ), - validator: (name) => name != null && name.isEmpty - ? 'You cannot leave this field empty!' - : null, - ); + autofocus: true, + controller: namecontroller, + style: TextStyle( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + decoration: InputDecoration( + hintText: 'Enter Task', + hintStyle: TextStyle( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + ), + validator: (name) => name != null && name.isEmpty + ? 'You cannot leave this field empty!' + : null, + ); Widget buildDueDate(BuildContext context) => Row( - children: [ - Text( - "Due : ", - style: GoogleFonts.poppins( + children: [ + Text( + "Due : ", + style: GoogleFonts.poppins( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + fontWeight: FontWeight.bold, + height: 3.3, + ), + ), + Expanded( + child: GestureDetector( + child: TextFormField( + style: TextStyle( color: AppSettings.isDarkMode ? Colors.white : Colors.black, - fontWeight: FontWeight.bold, - height: 3.3, ), - ), - Expanded( - child: GestureDetector( - child: TextFormField( - style: TextStyle( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - readOnly: true, - controller: TextEditingController( - text: (due != null) ? dueString : null, - ), - decoration: InputDecoration( - hintText: 'Select due date', - hintStyle: TextStyle( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - ), - onTap: () async { - var date = await showDatePicker( - builder: (BuildContext context, Widget? child) { - return Theme( - data: Theme.of(context).copyWith( - colorScheme: AppSettings.isDarkMode - ? const ColorScheme( - brightness: Brightness.dark, - primary: Colors.white, - onPrimary: Colors.black, - secondary: Colors.black, - onSecondary: Colors.white, - error: Colors.red, - onError: Colors.black, - background: Colors.black, - onBackground: Colors.white, - surface: Colors.black, - onSurface: Colors.white, - ) - : const ColorScheme( - brightness: Brightness.light, - primary: Colors.black, - onPrimary: Colors.white, - secondary: Colors.white, - onSecondary: Colors.black, - error: Colors.red, - onError: Colors.white, - background: Colors.white, - onBackground: Colors.black, - surface: Colors.white, - onSurface: Colors.black, - ), - ), - child: child!, - ); - }, - fieldHintText: "Month/Date/Year", - context: context, - initialDate: due ?? DateTime.now(), - firstDate: DateTime.now(), - lastDate: DateTime(2037, 12, 31), + readOnly: true, + controller: TextEditingController( + text: (due != null) ? dueString : null, + ), + decoration: InputDecoration( + hintText: 'Select due date', + hintStyle: TextStyle( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + ), + onTap: () async { + var date = await showDatePicker( + builder: (BuildContext context, Widget? child) { + return Theme( + data: Theme.of(context).copyWith( + colorScheme: AppSettings.isDarkMode + ? const ColorScheme( + brightness: Brightness.dark, + primary: Colors.white, + onPrimary: Colors.black, + secondary: Colors.black, + onSecondary: Colors.white, + error: Colors.red, + onError: Colors.black, + background: Colors.black, + onBackground: Colors.white, + surface: Colors.black, + onSurface: Colors.white, + ) + : const ColorScheme( + brightness: Brightness.light, + primary: Colors.black, + onPrimary: Colors.white, + secondary: Colors.white, + onSecondary: Colors.black, + error: Colors.red, + onError: Colors.white, + background: Colors.white, + onBackground: Colors.black, + surface: Colors.white, + onSurface: Colors.black, + ), + ), + child: child!, ); - if (date != null) { - var time = await showTimePicker( - builder: (BuildContext context, Widget? child) { - return Theme( - data: Theme.of(context).copyWith( - textTheme: const TextTheme(), - colorScheme: AppSettings.isDarkMode - ? const ColorScheme( - brightness: Brightness.dark, - primary: Colors.white, - onPrimary: Colors.black, - secondary: Color.fromARGB(255, 70, 68, 68), - onSecondary: Colors.white, - error: Colors.red, - onError: Colors.black, - background: Colors.black, - onBackground: Colors.white, - surface: Colors.black, - onSurface: Colors.white, - ) - : const ColorScheme( - brightness: Brightness.light, - primary: Colors.black, - onPrimary: Colors.white, - secondary: Colors.white, - onSecondary: Colors.black, - error: Colors.red, - onError: Colors.white, - background: Colors.white, - onBackground: Colors.black, - surface: Colors.white, - onSurface: Colors.black, - ), - ), - child: child!, - ); - }, - context: context, - initialTime: - TimeOfDay.fromDateTime(due ?? DateTime.now()), - ); - if (time != null) { - var dateTime = date.add( - Duration( - hours: time.hour, - minutes: time.minute, - ), - ); - dateTime = dateTime.add( - Duration( - hours: time.hour - dateTime.hour, + }, + fieldHintText: "Month/Date/Year", + context: context, + firstDate: DateTime.now(), + initialDate: due ?? DateTime.now(), + lastDate: DateTime(2037, 12, 31), + ); + + if (date != null) { + var time = await showTimePicker( + builder: (BuildContext context, Widget? child) { + return Theme( + data: Theme.of(context).copyWith( + textTheme: const TextTheme(), + colorScheme: AppSettings.isDarkMode + ? const ColorScheme( + brightness: Brightness.dark, + primary: Colors.white, + onPrimary: Colors.black, + secondary: Color.fromARGB(255, 70, 68, 68), + onSecondary: Colors.white, + error: Colors.red, + onError: Colors.black, + background: Colors.black, + onBackground: Colors.white, + surface: Colors.black, + onSurface: Colors.white, + ) + : const ColorScheme( + brightness: Brightness.light, + primary: Colors.black, + onPrimary: Colors.white, + secondary: Colors.white, + onSecondary: Colors.black, + error: Colors.red, + onError: Colors.white, + background: Colors.white, + onBackground: Colors.black, + surface: Colors.white, + onSurface: Colors.black, ), - ); - due = dateTime.toUtc(); - NotificationService notificationService = - NotificationService(); - notificationService.initiliazeNotification(); + ), + child: child!, + ); + }, + context: context, + initialTime: + TimeOfDay.fromDateTime(due ?? DateTime.now()), + ); - if ((dateTime.millisecondsSinceEpoch - - DateTime.now().millisecondsSinceEpoch) > - 0) { - notificationService.sendNotification( - dateTime, namecontroller.text); - } + if (time != null) { + var dateTime = date.add( + Duration( + hours: time.hour, + minutes: time.minute, + ), + ); + + if (dateTime.isAfter(DateTime.now())) { + due = dateTime.toUtc(); + NotificationService notificationService = + NotificationService(); + notificationService.initiliazeNotification(); + + notificationService.sendNotification( + dateTime, namecontroller.text); - dueString = - DateFormat("dd-MM-yyyy HH:mm").format(dateTime); - } + dueString = + DateFormat("dd-MM-yyyy HH:mm").format(dateTime); setState(() {}); + } else { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text( + 'Please select a due date and time in the future.', + style: TextStyle( + color: AppSettings.isDarkMode + ? Colors.white + : Colors.black, + ), + ), + backgroundColor: AppSettings.isDarkMode + ? Colors.black + : Colors.white, + duration: const Duration(seconds: 2), + )); } - }, - ), - ), + } + } + }, ), - ], - ); + ), + ), + ], + ); Widget buildPriority() => Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'Priority : ', - style: GoogleFonts.poppins( - fontWeight: FontWeight.bold, - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - textAlign: TextAlign.left, - ), - DropdownButton( - dropdownColor: AppSettings.isDarkMode - ? const Color.fromARGB(255, 25, 25, 25) - : Colors.white, - value: priority, - elevation: 16, - style: GoogleFonts.poppins( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - underline: Container( - height: 1.5, - color: AppSettings.isDarkMode - ? const Color.fromARGB(255, 25, 25, 25) - : Colors.white, - ), - onChanged: (String? newValue) { - setState(() { - priority = newValue!; - }); - }, - items: ['H', 'M', 'L', 'None'] - .map>((String value) { - return DropdownMenuItem( - value: value, - child: Text(' $value'), - ); - }).toList(), - ) - ], + Text( + 'Priority : ', + style: GoogleFonts.poppins( + fontWeight: FontWeight.bold, + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + textAlign: TextAlign.left, ), + DropdownButton( + dropdownColor: AppSettings.isDarkMode + ? const Color.fromARGB(255, 25, 25, 25) + : Colors.white, + value: priority, + elevation: 16, + style: GoogleFonts.poppins( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + underline: Container( + height: 1.5, + color: AppSettings.isDarkMode + ? const Color.fromARGB(255, 25, 25, 25) + : Colors.white, + ), + onChanged: (String? newValue) { + setState(() { + priority = newValue!; + }); + }, + items: ['H', 'M', 'L', 'None'] + .map>((String value) { + return DropdownMenuItem( + value: value, + child: Text(' $value'), + ); + }).toList(), + ) ], - ); + ), + ], + ); Widget buildCancelButton(BuildContext context) => TextButton( - child: Text( - 'Cancel', - style: TextStyle( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - ), - onPressed: () => Navigator.of(context).pop("cancel"), - ); + child: Text( + 'Cancel', + style: TextStyle( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + ), + onPressed: () => Navigator.of(context).pop("cancel"), + ); Widget buildAddButton(BuildContext context) { WidgetController widgetController = Get.put(WidgetController(context)); @@ -402,12 +410,12 @@ class _AddTaskBottomSheetState extends State { ), ), backgroundColor: - AppSettings.isDarkMode ? Colors.black : Colors.white, + AppSettings.isDarkMode ? Colors.black : Colors.white, duration: const Duration(seconds: 2), )); final SharedPreferences prefs = - await SharedPreferences.getInstance(); + await SharedPreferences.getInstance(); bool? value; value = prefs.getBool('sync-OnTaskCreate') ?? false; late InheritedStorage storageWidget; From 9e61c5f822c4e68901d6b5c1daa1b7af735a0367 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Thu, 1 Feb 2024 19:35:45 +0530 Subject: [PATCH 2/4] Make time after there --- lib/widgets/add_Task.dart | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/widgets/add_Task.dart b/lib/widgets/add_Task.dart index 2960ef02..708033b8 100644 --- a/lib/widgets/add_Task.dart +++ b/lib/widgets/add_Task.dart @@ -13,7 +13,7 @@ import 'package:taskwarrior/widgets/taskfunctions/taskparser.dart'; import 'package:taskwarrior/widgets/taskw.dart'; class AddTaskBottomSheet extends StatefulWidget { - const AddTaskBottomSheet({super.key}); + const AddTaskBottomSheet({Key? key}) : super(key: key); @override _AddTaskBottomSheetState createState() => _AddTaskBottomSheetState(); @@ -21,11 +21,11 @@ class AddTaskBottomSheet extends StatefulWidget { class _AddTaskBottomSheetState extends State { final formKey = GlobalKey(); - final namecontroller = TextEditingController(); + final nameController = TextEditingController(); DateTime? due; String dueString = ''; String priority = 'M'; - final tagcontroller = TextEditingController(); + final tagController = TextEditingController(); List tags = []; @override @@ -35,8 +35,8 @@ class _AddTaskBottomSheetState extends State { @override void dispose() { - tagcontroller.dispose(); - namecontroller.dispose(); + tagController.dispose(); + nameController.dispose(); super.dispose(); } @@ -101,7 +101,7 @@ class _AddTaskBottomSheetState extends State { children: [ Expanded( child: TextFormField( - controller: tagcontroller, + controller: tagController, style: TextStyle( color: AppSettings.isDarkMode ? Colors.white : Colors.black, ), @@ -118,7 +118,7 @@ class _AddTaskBottomSheetState extends State { ), IconButton( onPressed: () { - addTag(tagcontroller.text.trim()); + addTag(tagController.text.trim()); }, icon: const Icon(Icons.add), ), @@ -141,7 +141,7 @@ class _AddTaskBottomSheetState extends State { Widget buildName() => TextFormField( autofocus: true, - controller: namecontroller, + controller: nameController, style: TextStyle( color: AppSettings.isDarkMode ? Colors.white : Colors.black, ), @@ -220,8 +220,8 @@ class _AddTaskBottomSheetState extends State { }, fieldHintText: "Month/Date/Year", context: context, - firstDate: DateTime.now(), initialDate: due ?? DateTime.now(), + firstDate: DateTime.now(), lastDate: DateTime(2037, 12, 31), ); @@ -263,8 +263,7 @@ class _AddTaskBottomSheetState extends State { ); }, context: context, - initialTime: - TimeOfDay.fromDateTime(due ?? DateTime.now()), + initialTime: TimeOfDay.fromDateTime(due ?? DateTime.now()), ); if (time != null) { @@ -282,10 +281,9 @@ class _AddTaskBottomSheetState extends State { notificationService.initiliazeNotification(); notificationService.sendNotification( - dateTime, namecontroller.text); + dateTime, nameController.text); - dueString = - DateFormat("dd-MM-yyyy HH:mm").format(dateTime); + dueString = DateFormat("dd-MM-yyyy HH:mm").format(dateTime); setState(() {}); } else { ScaffoldMessenger.of(context).showSnackBar(SnackBar( @@ -382,21 +380,21 @@ class _AddTaskBottomSheetState extends State { onPressed: () async { if (formKey.currentState!.validate()) { try { - var task = taskParser(namecontroller.text) + var task = taskParser(nameController.text) .rebuild((b) => b..due = due) .rebuild((p) => p..priority = priority); - if (tagcontroller.text != "") { - tags.add(tagcontroller.text.trim()); + if (tagController.text != "") { + tags.add(tagController.text.trim()); } if (tags.isNotEmpty) { task = task.rebuild((t) => t..tags.replace(tags)); } StorageWidget.of(context).mergeTask(task); - namecontroller.text = ''; + nameController.text = ''; due = null; priority = 'M'; - tagcontroller.text = ''; + tagController.text = ''; tags = []; setState(() {}); Navigator.of(context).pop(); @@ -448,7 +446,7 @@ class _AddTaskBottomSheetState extends State { setState(() { String trimmedString = tag.trim(); tags.add(trimmedString); - tagcontroller.text = ''; + tagController.text = ''; }); } } From 6668475872bba5e5a19e4d40d230a0f1b2de4317 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Thu, 1 Feb 2024 20:05:00 +0530 Subject: [PATCH 3/4] Make time after there --- lib/widgets/add_Task.dart | 82 ++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 44 deletions(-) diff --git a/lib/widgets/add_Task.dart b/lib/widgets/add_Task.dart index 708033b8..d04ed9e1 100644 --- a/lib/widgets/add_Task.dart +++ b/lib/widgets/add_Task.dart @@ -1,3 +1,5 @@ +// ignore_for_file: library_private_types_in_public_api, use_build_context_synchronously, file_names + import 'dart:developer'; import 'package:flutter/material.dart'; @@ -13,7 +15,7 @@ import 'package:taskwarrior/widgets/taskfunctions/taskparser.dart'; import 'package:taskwarrior/widgets/taskw.dart'; class AddTaskBottomSheet extends StatefulWidget { - const AddTaskBottomSheet({Key? key}) : super(key: key); + const AddTaskBottomSheet({super.key}); @override _AddTaskBottomSheetState createState() => _AddTaskBottomSheetState(); @@ -21,11 +23,11 @@ class AddTaskBottomSheet extends StatefulWidget { class _AddTaskBottomSheetState extends State { final formKey = GlobalKey(); - final nameController = TextEditingController(); + final namecontroller = TextEditingController(); DateTime? due; String dueString = ''; String priority = 'M'; - final tagController = TextEditingController(); + final tagcontroller = TextEditingController(); List tags = []; @override @@ -35,8 +37,8 @@ class _AddTaskBottomSheetState extends State { @override void dispose() { - tagController.dispose(); - nameController.dispose(); + tagcontroller.dispose(); + namecontroller.dispose(); super.dispose(); } @@ -101,7 +103,7 @@ class _AddTaskBottomSheetState extends State { children: [ Expanded( child: TextFormField( - controller: tagController, + controller: tagcontroller, style: TextStyle( color: AppSettings.isDarkMode ? Colors.white : Colors.black, ), @@ -116,11 +118,12 @@ class _AddTaskBottomSheetState extends State { }, ), ), + // Replace ElevatedButton with IconButton IconButton( onPressed: () { - addTag(tagController.text.trim()); + addTag(tagcontroller.text.trim()); }, - icon: const Icon(Icons.add), + icon: const Icon(Icons.add), // Plus icon ), ], ), @@ -141,7 +144,7 @@ class _AddTaskBottomSheetState extends State { Widget buildName() => TextFormField( autofocus: true, - controller: nameController, + controller: namecontroller, style: TextStyle( color: AppSettings.isDarkMode ? Colors.white : Colors.black, ), @@ -224,7 +227,6 @@ class _AddTaskBottomSheetState extends State { firstDate: DateTime.now(), lastDate: DateTime(2037, 12, 31), ); - if (date != null) { var time = await showTimePicker( builder: (BuildContext context, Widget? child) { @@ -263,9 +265,9 @@ class _AddTaskBottomSheetState extends State { ); }, context: context, - initialTime: TimeOfDay.fromDateTime(due ?? DateTime.now()), + initialTime: + TimeOfDay.fromDateTime(due ?? DateTime.now()), ); - if (time != null) { var dateTime = date.add( Duration( @@ -273,35 +275,27 @@ class _AddTaskBottomSheetState extends State { minutes: time.minute, ), ); + dateTime = dateTime.add( + Duration( + hours: time.hour - dateTime.hour, + ), + ); + due = dateTime.toUtc(); + NotificationService notificationService = + NotificationService(); + notificationService.initiliazeNotification(); - if (dateTime.isAfter(DateTime.now())) { - due = dateTime.toUtc(); - NotificationService notificationService = - NotificationService(); - notificationService.initiliazeNotification(); - + if ((dateTime.millisecondsSinceEpoch - + DateTime.now().millisecondsSinceEpoch) > + 0) { notificationService.sendNotification( - dateTime, nameController.text); - - dueString = DateFormat("dd-MM-yyyy HH:mm").format(dateTime); - setState(() {}); - } else { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text( - 'Please select a due date and time in the future.', - style: TextStyle( - color: AppSettings.isDarkMode - ? Colors.white - : Colors.black, - ), - ), - backgroundColor: AppSettings.isDarkMode - ? Colors.black - : Colors.white, - duration: const Duration(seconds: 2), - )); + dateTime, namecontroller.text); } + + dueString = + DateFormat("dd-MM-yyyy HH:mm").format(dateTime); } + setState(() {}); } }, ), @@ -380,21 +374,21 @@ class _AddTaskBottomSheetState extends State { onPressed: () async { if (formKey.currentState!.validate()) { try { - var task = taskParser(nameController.text) + var task = taskParser(namecontroller.text) .rebuild((b) => b..due = due) .rebuild((p) => p..priority = priority); - if (tagController.text != "") { - tags.add(tagController.text.trim()); + if (tagcontroller.text != "") { + tags.add(tagcontroller.text.trim()); } if (tags.isNotEmpty) { task = task.rebuild((t) => t..tags.replace(tags)); } StorageWidget.of(context).mergeTask(task); - nameController.text = ''; + namecontroller.text = ''; due = null; priority = 'M'; - tagController.text = ''; + tagcontroller.text = ''; tags = []; setState(() {}); Navigator.of(context).pop(); @@ -446,7 +440,7 @@ class _AddTaskBottomSheetState extends State { setState(() { String trimmedString = tag.trim(); tags.add(trimmedString); - tagController.text = ''; + tagcontroller.text = ''; }); } } @@ -456,4 +450,4 @@ class _AddTaskBottomSheetState extends State { tags.remove(tag); }); } -} +} \ No newline at end of file From 4a056256f57ec8a8c7ef84d1b2ca84c15bb54f81 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Thu, 1 Feb 2024 20:13:32 +0530 Subject: [PATCH 4/4] Make time after there --- lib/widgets/add_Task.dart | 416 +++++++++++++++++++------------------- 1 file changed, 212 insertions(+), 204 deletions(-) diff --git a/lib/widgets/add_Task.dart b/lib/widgets/add_Task.dart index d04ed9e1..24226e6e 100644 --- a/lib/widgets/add_Task.dart +++ b/lib/widgets/add_Task.dart @@ -143,223 +143,231 @@ class _AddTaskBottomSheetState extends State { } Widget buildName() => TextFormField( - autofocus: true, - controller: namecontroller, - style: TextStyle( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - decoration: InputDecoration( - hintText: 'Enter Task', - hintStyle: TextStyle( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - ), - validator: (name) => name != null && name.isEmpty - ? 'You cannot leave this field empty!' - : null, - ); - - Widget buildDueDate(BuildContext context) => Row( - children: [ - Text( - "Due : ", - style: GoogleFonts.poppins( + autofocus: true, + controller: namecontroller, + style: TextStyle( color: AppSettings.isDarkMode ? Colors.white : Colors.black, - fontWeight: FontWeight.bold, - height: 3.3, ), - ), - Expanded( - child: GestureDetector( - child: TextFormField( - style: TextStyle( + decoration: InputDecoration( + hintText: 'Enter Task', + hintStyle: TextStyle( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + ), + validator: (name) => name != null && name.isEmpty + ? 'You cannot leave this field empty!' + : null, + ); + + Widget buildDueDate(BuildContext context) => Row( + children: [ + Text( + "Due : ", + style: GoogleFonts.poppins( color: AppSettings.isDarkMode ? Colors.white : Colors.black, + fontWeight: FontWeight.bold, + height: 3.3, ), - readOnly: true, - controller: TextEditingController( - text: (due != null) ? dueString : null, - ), - decoration: InputDecoration( - hintText: 'Select due date', - hintStyle: TextStyle( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - ), - onTap: () async { - var date = await showDatePicker( - builder: (BuildContext context, Widget? child) { - return Theme( - data: Theme.of(context).copyWith( - colorScheme: AppSettings.isDarkMode - ? const ColorScheme( - brightness: Brightness.dark, - primary: Colors.white, - onPrimary: Colors.black, - secondary: Colors.black, - onSecondary: Colors.white, - error: Colors.red, - onError: Colors.black, - background: Colors.black, - onBackground: Colors.white, - surface: Colors.black, - onSurface: Colors.white, - ) - : const ColorScheme( - brightness: Brightness.light, - primary: Colors.black, - onPrimary: Colors.white, - secondary: Colors.white, - onSecondary: Colors.black, - error: Colors.red, - onError: Colors.white, - background: Colors.white, - onBackground: Colors.black, - surface: Colors.white, - onSurface: Colors.black, - ), - ), - child: child!, - ); - }, - fieldHintText: "Month/Date/Year", - context: context, - initialDate: due ?? DateTime.now(), - firstDate: DateTime.now(), - lastDate: DateTime(2037, 12, 31), - ); - if (date != null) { - var time = await showTimePicker( - builder: (BuildContext context, Widget? child) { - return Theme( - data: Theme.of(context).copyWith( - textTheme: const TextTheme(), - colorScheme: AppSettings.isDarkMode - ? const ColorScheme( - brightness: Brightness.dark, - primary: Colors.white, - onPrimary: Colors.black, - secondary: Color.fromARGB(255, 70, 68, 68), - onSecondary: Colors.white, - error: Colors.red, - onError: Colors.black, - background: Colors.black, - onBackground: Colors.white, - surface: Colors.black, - onSurface: Colors.white, - ) - : const ColorScheme( - brightness: Brightness.light, - primary: Colors.black, - onPrimary: Colors.white, - secondary: Colors.white, - onSecondary: Colors.black, - error: Colors.red, - onError: Colors.white, - background: Colors.white, - onBackground: Colors.black, - surface: Colors.white, - onSurface: Colors.black, + ), + Expanded( + child: GestureDetector( + child: TextFormField( + style: TextStyle( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + readOnly: true, + controller: TextEditingController( + text: (due != null) ? dueString : null, + ), + decoration: InputDecoration( + hintText: 'Select due date', + hintStyle: TextStyle( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + ), + onTap: () async { + var date = await showDatePicker( + builder: (BuildContext context, Widget? child) { + return Theme( + data: Theme.of(context).copyWith( + colorScheme: AppSettings.isDarkMode + ? const ColorScheme( + brightness: Brightness.dark, + primary: Colors.white, + onPrimary: Colors.black, + secondary: Colors.black, + onSecondary: Colors.white, + error: Colors.red, + onError: Colors.black, + background: Colors.black, + onBackground: Colors.white, + surface: Colors.black, + onSurface: Colors.white, + ) + : const ColorScheme( + brightness: Brightness.light, + primary: Colors.black, + onPrimary: Colors.white, + secondary: Colors.white, + onSecondary: Colors.black, + error: Colors.red, + onError: Colors.white, + background: Colors.white, + onBackground: Colors.black, + surface: Colors.white, + onSurface: Colors.black, + ), ), - ), - child: child!, - ); - }, - context: context, - initialTime: - TimeOfDay.fromDateTime(due ?? DateTime.now()), - ); - if (time != null) { - var dateTime = date.add( - Duration( - hours: time.hour, - minutes: time.minute, - ), - ); - dateTime = dateTime.add( - Duration( - hours: time.hour - dateTime.hour, - ), + child: child!, + ); + }, + fieldHintText: "Month/Date/Year", + context: context, + initialDate: due ?? DateTime.now(), + firstDate: DateTime.now(), + lastDate: DateTime(2037, 12, 31), ); - due = dateTime.toUtc(); - NotificationService notificationService = - NotificationService(); - notificationService.initiliazeNotification(); + if (date != null) { + var time = await showTimePicker( + builder: (BuildContext context, Widget? child) { + return Theme( + data: Theme.of(context).copyWith( + textTheme: const TextTheme(), + colorScheme: AppSettings.isDarkMode + ? const ColorScheme( + brightness: Brightness.dark, + primary: Colors.white, + onPrimary: Colors.black, + secondary: Color.fromARGB(255, 70, 68, 68), + onSecondary: Colors.white, + error: Colors.red, + onError: Colors.black, + background: Colors.black, + onBackground: Colors.white, + surface: Colors.black, + onSurface: Colors.white, + ) + : const ColorScheme( + brightness: Brightness.light, + primary: Colors.black, + onPrimary: Colors.white, + secondary: Colors.white, + onSecondary: Colors.black, + error: Colors.red, + onError: Colors.white, + background: Colors.white, + onBackground: Colors.black, + surface: Colors.white, + onSurface: Colors.black, + ), + ), + child: child!, + ); + }, + context: context, + initialTime: + TimeOfDay.fromDateTime(due ?? DateTime.now()), + ); + if (time != null) { + var dateTime = date.add( + Duration( + hours: time.hour, + minutes: time.minute, + ), + ); + if (dateTime.isAfter(DateTime.now())) { + due = dateTime.toUtc(); + NotificationService notificationService = + NotificationService(); + notificationService.initiliazeNotification(); - if ((dateTime.millisecondsSinceEpoch - - DateTime.now().millisecondsSinceEpoch) > - 0) { - notificationService.sendNotification( - dateTime, namecontroller.text); - } + notificationService.sendNotification( + dateTime, namecontroller.text); - dueString = - DateFormat("dd-MM-yyyy HH:mm").format(dateTime); - } - setState(() {}); - } - }, + dueString = + DateFormat("dd-MM-yyyy HH:mm").format(dateTime); + setState(() {}); + } else { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text( + 'Please select a due date and time in the future.', + style: TextStyle( + color: AppSettings.isDarkMode + ? Colors.white + : Colors.black, + ), + ), + backgroundColor: AppSettings.isDarkMode + ? Colors.black + : Colors.white, + duration: const Duration(seconds: 2), + )); + } + } + } + }, + ), + ), ), - ), - ), - ], - ); + ], + ); Widget buildPriority() => Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, children: [ - Text( - 'Priority : ', - style: GoogleFonts.poppins( - fontWeight: FontWeight.bold, - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - textAlign: TextAlign.left, + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + 'Priority : ', + style: GoogleFonts.poppins( + fontWeight: FontWeight.bold, + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + textAlign: TextAlign.left, + ), + DropdownButton( + dropdownColor: AppSettings.isDarkMode + ? const Color.fromARGB(255, 25, 25, 25) + : Colors.white, + value: priority, + elevation: 16, + style: GoogleFonts.poppins( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + underline: Container( + height: 1.5, + color: AppSettings.isDarkMode + ? const Color.fromARGB(255, 25, 25, 25) + : Colors.white, + ), + onChanged: (String? newValue) { + setState(() { + priority = newValue!; + }); + }, + items: ['H', 'M', 'L', 'None'] + .map>((String value) { + return DropdownMenuItem( + value: value, + child: Text(' $value'), + ); + }).toList(), + ) + ], ), - DropdownButton( - dropdownColor: AppSettings.isDarkMode - ? const Color.fromARGB(255, 25, 25, 25) - : Colors.white, - value: priority, - elevation: 16, - style: GoogleFonts.poppins( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - underline: Container( - height: 1.5, - color: AppSettings.isDarkMode - ? const Color.fromARGB(255, 25, 25, 25) - : Colors.white, - ), - onChanged: (String? newValue) { - setState(() { - priority = newValue!; - }); - }, - items: ['H', 'M', 'L', 'None'] - .map>((String value) { - return DropdownMenuItem( - value: value, - child: Text(' $value'), - ); - }).toList(), - ) ], - ), - ], - ); + ); Widget buildCancelButton(BuildContext context) => TextButton( - child: Text( - 'Cancel', - style: TextStyle( - color: AppSettings.isDarkMode ? Colors.white : Colors.black, - ), - ), - onPressed: () => Navigator.of(context).pop("cancel"), - ); + child: Text( + 'Cancel', + style: TextStyle( + color: AppSettings.isDarkMode ? Colors.white : Colors.black, + ), + ), + onPressed: () => Navigator.of(context).pop("cancel"), + ); Widget buildAddButton(BuildContext context) { WidgetController widgetController = Get.put(WidgetController(context)); @@ -402,12 +410,12 @@ class _AddTaskBottomSheetState extends State { ), ), backgroundColor: - AppSettings.isDarkMode ? Colors.black : Colors.white, + AppSettings.isDarkMode ? Colors.black : Colors.white, duration: const Duration(seconds: 2), )); final SharedPreferences prefs = - await SharedPreferences.getInstance(); + await SharedPreferences.getInstance(); bool? value; value = prefs.getBool('sync-OnTaskCreate') ?? false; late InheritedStorage storageWidget; @@ -450,4 +458,4 @@ class _AddTaskBottomSheetState extends State { tags.remove(tag); }); } -} \ No newline at end of file +}