From ca8bc26ab5347222da60b81e7f305b68d428aa5a Mon Sep 17 00:00:00 2001 From: Vaibhav Surve Date: Thu, 19 Jun 2025 18:02:37 +0530 Subject: [PATCH] feat: Refactor showCreateTaskBottomSheet for improved structure and readability --- .../create_task_botom_sheet.dart | 333 ++++++++++-------- 1 file changed, 177 insertions(+), 156 deletions(-) diff --git a/lib/model/dailyTaskPlaning/create_task_botom_sheet.dart b/lib/model/dailyTaskPlaning/create_task_botom_sheet.dart index 17e5e10..2ca2e3f 100644 --- a/lib/model/dailyTaskPlaning/create_task_botom_sheet.dart +++ b/lib/model/dailyTaskPlaning/create_task_botom_sheet.dart @@ -35,168 +35,188 @@ void showCreateTaskBottomSheet({ return // Inside showManageTaskBottomSheet... -SafeArea( - child: Material( - color: Colors.white, - borderRadius: const BorderRadius.vertical(top: Radius.circular(20)), - child: Container( - constraints: const BoxConstraints(maxHeight: 760), - padding: EdgeInsets.fromLTRB(horizontalPadding, 12, horizontalPadding, 24), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Center( - child: Container( - width: 40, - height: 4, - margin: const EdgeInsets.only(bottom: 16), - decoration: BoxDecoration( - color: Colors.grey.shade400, - borderRadius: BorderRadius.circular(2), - ), - ), - ), - Center( - child: MyText.titleLarge( - "Create Task", - fontWeight: 700, - ), - ), - const SizedBox(height: 20), - _infoCardSection([ - _infoRowWithIcon(Icons.workspaces, "Selected Work Area", workArea), - _infoRowWithIcon(Icons.list_alt, "Selected Activity", activity), - _infoRowWithIcon(Icons.check_circle_outline, "Completed Work", completedWork), - ]), - const SizedBox(height: 16), - _sectionTitle(Icons.edit_calendar, "Planned Work"), - const SizedBox(height: 6), - _customTextField( - controller: plannedTaskController, - hint: "Enter planned work", - keyboardType: TextInputType.number, - ), - const SizedBox(height: 16), - _sectionTitle(Icons.description_outlined, "Comment"), - const SizedBox(height: 6), - _customTextField( - controller: descriptionController, - hint: "Enter task description", - maxLines: 3, - ), - const SizedBox(height: 16), - _sectionTitle(Icons.category_outlined, "Selected Work Category"), - const SizedBox(height: 6), - Obx(() { - final categoryMap = controller.categoryIdNameMap; - final String selectedName = - controller.selectedCategoryId.value != null - ? (categoryMap[controller.selectedCategoryId.value!] ?? 'Select Category') - : 'Select Category'; - - return Container( - width: double.infinity, - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14), - decoration: BoxDecoration( - color: Colors.grey.shade100, - border: Border.all(color: Colors.grey.shade300), - borderRadius: BorderRadius.circular(8), - ), - child: PopupMenuButton( - padding: EdgeInsets.zero, - onSelected: (val) { - controller.selectCategory(val); - onCategoryChanged(val); - }, - itemBuilder: (context) => categoryMap.entries - .map( - (entry) => PopupMenuItem( - value: entry.key, - child: Text(entry.value), + SafeArea( + child: Material( + color: Colors.white, + borderRadius: + const BorderRadius.vertical(top: Radius.circular(20)), + child: Container( + constraints: const BoxConstraints(maxHeight: 760), + padding: EdgeInsets.fromLTRB( + horizontalPadding, 12, horizontalPadding, 24), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Center( + child: Container( + width: 40, + height: 4, + margin: const EdgeInsets.only(bottom: 16), + decoration: BoxDecoration( + color: Colors.grey.shade400, + borderRadius: BorderRadius.circular(2), + ), + ), ), - ) - .toList(), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - selectedName, - style: const TextStyle(fontSize: 14, color: Colors.black87), - ), - const Icon(Icons.arrow_drop_down), - ], - ), - ), - ); - }), - const SizedBox(height: 24), - Row( - children: [ - Expanded( - child: OutlinedButton.icon( - onPressed: () => Get.back(), - icon: const Icon(Icons.close, size: 18), - label: MyText.bodyMedium("Cancel", fontWeight: 600), - style: OutlinedButton.styleFrom( - side: const BorderSide(color: Colors.grey), - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), - ), - ), - ), - const SizedBox(width: 12), - Expanded( - child: ElevatedButton.icon( - onPressed: () async { - final plannedValue = int.tryParse(plannedTaskController.text.trim()) ?? 0; - final comment = descriptionController.text.trim(); - final selectedCategoryId = controller.selectedCategoryId.value; - if (selectedCategoryId == null) { - showAppSnackbar( - title: "error", - message: "Please select a work category!", - type: SnackbarType.error, - ); - return; - } + Center( + child: MyText.titleLarge( + "Create Task", + fontWeight: 700, + ), + ), + const SizedBox(height: 20), + _infoCardSection([ + _infoRowWithIcon( + Icons.workspaces, "Selected Work Area", workArea), + _infoRowWithIcon( + Icons.list_alt, "Selected Activity", activity), + _infoRowWithIcon(Icons.check_circle_outline, + "Completed Work", completedWork), + ]), + const SizedBox(height: 16), + _sectionTitle(Icons.edit_calendar, "Planned Work"), + const SizedBox(height: 6), + _customTextField( + controller: plannedTaskController, + hint: "Enter planned work", + keyboardType: TextInputType.number, + ), + const SizedBox(height: 16), + _sectionTitle(Icons.description_outlined, "Comment"), + const SizedBox(height: 6), + _customTextField( + controller: descriptionController, + hint: "Enter task description", + maxLines: 3, + ), + const SizedBox(height: 16), + _sectionTitle( + Icons.category_outlined, "Selected Work Category"), + const SizedBox(height: 6), + Obx(() { + final categoryMap = controller.categoryIdNameMap; + final String selectedName = + controller.selectedCategoryId.value != null + ? (categoryMap[controller + .selectedCategoryId.value!] ?? + 'Select Category') + : 'Select Category'; - final success = await controller.createTask( - parentTaskId: parentTaskId, - plannedTask: plannedValue, - comment: comment, - workAreaId: workAreaId, - activityId: activityId, - categoryId: selectedCategoryId, - ); - - if (success) { - Get.back(); - Future.delayed(const Duration(milliseconds: 300), () { - onSubmit(); - showAppSnackbar( - title: "Success", - message: "Task created successfully!", - type: SnackbarType.success, + return Container( + width: double.infinity, + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 14), + decoration: BoxDecoration( + color: Colors.grey.shade100, + border: Border.all(color: Colors.grey.shade300), + borderRadius: BorderRadius.circular(8), + ), + child: PopupMenuButton( + padding: EdgeInsets.zero, + onSelected: (val) { + controller.selectCategory(val); + onCategoryChanged(val); + }, + itemBuilder: (context) => categoryMap.entries + .map( + (entry) => PopupMenuItem( + value: entry.key, + child: Text(entry.value), + ), + ) + .toList(), + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Text( + selectedName, + style: const TextStyle( + fontSize: 14, color: Colors.black87), + ), + const Icon(Icons.arrow_drop_down), + ], + ), + ), ); - }); - } - }, - icon: const Icon(Icons.check, size: 18), - label: MyText.bodyMedium("Submit", color: Colors.white, fontWeight: 600), - style: ElevatedButton.styleFrom( - backgroundColor: Colors.blueAccent, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), + }), + const SizedBox(height: 24), + Row( + children: [ + Expanded( + child: OutlinedButton.icon( + onPressed: () => Get.back(), + icon: const Icon(Icons.close, size: 18), + label: MyText.bodyMedium("Cancel", + fontWeight: 600), + style: OutlinedButton.styleFrom( + side: const BorderSide(color: Colors.grey), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10)), + ), + ), + ), + const SizedBox(width: 12), + Expanded( + child: ElevatedButton.icon( + onPressed: () async { + final plannedValue = int.tryParse( + plannedTaskController.text.trim()) ?? + 0; + final comment = + descriptionController.text.trim(); + final selectedCategoryId = + controller.selectedCategoryId.value; + if (selectedCategoryId == null) { + showAppSnackbar( + title: "error", + message: "Please select a work category!", + type: SnackbarType.error, + ); + return; + } + + final success = await controller.createTask( + parentTaskId: parentTaskId, + plannedTask: plannedValue, + comment: comment, + workAreaId: workAreaId, + activityId: activityId, + categoryId: selectedCategoryId, + ); + + if (success) { + Get.back(); + Future.delayed( + const Duration(milliseconds: 300), () { + onSubmit(); + showAppSnackbar( + title: "Success", + message: "Task created successfully!", + type: SnackbarType.success, + ); + }); + } + }, + icon: const Icon(Icons.check, size: 18), + label: MyText.bodyMedium("Submit", + color: Colors.white, fontWeight: 600), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.blueAccent, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10)), + ), + ), + ), + ], + ), + ], ), ), ), - ], - ), - ], - ), - ), - ), - ), -); + ), + ); }, ); }, @@ -204,6 +224,7 @@ SafeArea( isScrollControlled: true, ); } + Widget _sectionTitle(IconData icon, String title) { return Row( children: [