diff --git a/lib/model/dailyTaskPlaning/assign_task_bottom_sheet .dart b/lib/model/dailyTaskPlaning/assign_task_bottom_sheet .dart index 413cf17..0bcd385 100644 --- a/lib/model/dailyTaskPlaning/assign_task_bottom_sheet .dart +++ b/lib/model/dailyTaskPlaning/assign_task_bottom_sheet .dart @@ -53,7 +53,7 @@ class _AssignTaskBottomSheetState extends State { @override void initState() { super.initState(); - selectedProjectId = projectController.selectedProjectId?.value; + selectedProjectId = projectController.selectedProjectId.value; WidgetsBinding.instance.addPostFrameCallback((_) { if (selectedProjectId != null) { @@ -147,7 +147,6 @@ class _AssignTaskBottomSheetState extends State { child: _buildEmployeeList(), ), MySpacing.height(8), - Obx(() { if (controller.selectedEmployees.isEmpty) return Container(); @@ -179,7 +178,6 @@ class _AssignTaskBottomSheetState extends State { ), ); }), - _buildTextField( icon: Icons.track_changes, label: "Target for Today :", @@ -189,7 +187,6 @@ class _AssignTaskBottomSheetState extends State { validatorType: "target", ), MySpacing.height(24), - _buildTextField( icon: Icons.description, label: "Description :", @@ -199,7 +196,6 @@ class _AssignTaskBottomSheetState extends State { validatorType: "description", ), MySpacing.height(24), - Row( mainAxisAlignment: MainAxisAlignment.end, children: [ diff --git a/lib/model/dailyTaskPlaning/comment_task_bottom_sheet.dart b/lib/model/dailyTaskPlaning/comment_task_bottom_sheet.dart index a968260..90ab576 100644 --- a/lib/model/dailyTaskPlaning/comment_task_bottom_sheet.dart +++ b/lib/model/dailyTaskPlaning/comment_task_bottom_sheet.dart @@ -12,15 +12,21 @@ import 'package:marco/helpers/widgets/my_team_model_sheet.dart'; import 'package:intl/intl.dart'; import 'package:marco/helpers/widgets/image_viewer_dialog.dart'; import 'dart:io'; +import 'package:marco/model/dailyTaskPlaning/create_task_botom_sheet.dart'; class CommentTaskBottomSheet extends StatefulWidget { final Map taskData; final VoidCallback? onCommentSuccess; - + final String taskDataId; + final String workAreaId; + final String activityId; const CommentTaskBottomSheet({ super.key, required this.taskData, this.onCommentSuccess, + required this.taskDataId, + required this.workAreaId, + required this.activityId, }); @override @@ -128,17 +134,72 @@ class _CommentTaskBottomSheetState extends State child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - MyText.titleMedium( - "Comment Task", - fontWeight: 600, - fontSize: 18, + MySpacing.height(12), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + MyText.titleMedium( + "Comment Task", + fontWeight: 600, + fontSize: 18, + ), + ], + ), + const SizedBox(height: 12), + + // Second row: Right-aligned "+ Create Task" button + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + InkWell( + onTap: () { + showCreateTaskBottomSheet( + workArea: + widget.taskData['location'] ?? '', + activity: + widget.taskData['activity'] ?? '', + completedWork: + widget.taskData['completedWork'] ?? + '', + unit: widget.taskData['unit'] ?? '', + onCategoryChanged: (category) { + debugPrint( + "Category changed to: $category"); + }, + parentTaskId: widget.taskDataId, + plannedTask: int.tryParse( + widget.taskData['plannedWork'] ?? + '0') ?? + 0, + activityId: widget.activityId, + workAreaId: widget.workAreaId, + onSubmit: () { + Navigator.of(context).pop(); + }, + ); + }, + borderRadius: BorderRadius.circular(16), + child: Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 6), + decoration: BoxDecoration( + color: Colors.blueAccent.withOpacity(0.1), + borderRadius: BorderRadius.circular(16), + ), + child: MyText.bodySmall( + "+ Create Task", + fontWeight: 600, + color: Colors.blueAccent, + ), + ), + ), + ], ), ], ), - MySpacing.height(24), buildRow( "Assigned By", controller.basicValidator diff --git a/lib/model/dailyTaskPlaning/task_action_buttons.dart b/lib/model/dailyTaskPlaning/task_action_buttons.dart index fd2a5fe..bf550fd 100644 --- a/lib/model/dailyTaskPlaning/task_action_buttons.dart +++ b/lib/model/dailyTaskPlaning/task_action_buttons.dart @@ -72,6 +72,9 @@ class TaskActionButtons { required BuildContext context, required dynamic task, required VoidCallback refreshCallback, + required String parentTaskID, + required String activityId, + required String workAreaId, }) { return OutlinedButton.icon( icon: const Icon(Icons.comment, size: 18, color: Colors.blueAccent), @@ -82,7 +85,8 @@ class TaskActionButtons { textStyle: const TextStyle(fontSize: 14), ), onPressed: () { - final taskData = _prepareTaskData(task: task, completed: task.completedTask.toInt()); + final taskData = + _prepareTaskData(task: task, completed: task.completedTask.toInt()); showModalBottomSheet( context: context, @@ -90,6 +94,9 @@ class TaskActionButtons { backgroundColor: Colors.transparent, builder: (_) => CommentTaskBottomSheet( taskData: taskData, + taskDataId: parentTaskID, + workAreaId: workAreaId, + activityId: activityId, onCommentSuccess: () { refreshCallback(); Navigator.of(context).pop(); diff --git a/lib/view/taskPlaning/daily_progress.dart b/lib/view/taskPlaning/daily_progress.dart index 9d81018..8a7e8a4 100644 --- a/lib/view/taskPlaning/daily_progress.dart +++ b/lib/view/taskPlaning/daily_progress.dart @@ -44,29 +44,23 @@ class _DailyProgressReportScreenState extends State void initState() { super.initState(); - final initialProjectId = projectController.selectedProjectId?.value; - if (initialProjectId != null) { + final initialProjectId = projectController.selectedProjectId.value; + if (initialProjectId.isNotEmpty) { dailyTaskController.selectedProjectId = initialProjectId; dailyTaskController.fetchTaskData(initialProjectId); } - final selectedProjectIdRx = projectController.selectedProjectId; - if (selectedProjectIdRx != null) { - ever( - selectedProjectIdRx, - (newProjectId) async { - if (newProjectId != null && - newProjectId != dailyTaskController.selectedProjectId) { - dailyTaskController.selectedProjectId = newProjectId; - await dailyTaskController.fetchTaskData(newProjectId); - dailyTaskController.update(['daily_progress_report_controller']); - } - }, - ); - } else { - debugPrint( - "Warning: selectedProjectId is null, skipping listener setup."); - } + ever( + projectController.selectedProjectId, + (newProjectId) async { + if (newProjectId.isNotEmpty && + newProjectId != dailyTaskController.selectedProjectId) { + dailyTaskController.selectedProjectId = newProjectId; + await dailyTaskController.fetchTaskData(newProjectId); + dailyTaskController.update(['daily_progress_report_controller']); + } + }, + ); } @override @@ -486,6 +480,9 @@ class _DailyProgressReportScreenState extends State TaskActionButtons.commentButton( context: context, task: task, + parentTaskID: parentTaskID, + workAreaId: workAreaId.toString(), + activityId: activityId.toString(), refreshCallback: _refreshData, ), ], diff --git a/lib/view/taskPlaning/daily_task_planing.dart b/lib/view/taskPlaning/daily_task_planing.dart index b28fa77..0e96a60 100644 --- a/lib/view/taskPlaning/daily_task_planing.dart +++ b/lib/view/taskPlaning/daily_task_planing.dart @@ -33,23 +33,20 @@ class _DailyTaskPlaningScreenState extends State super.initState(); // Initial fetch if a project is already selected - final projectId = projectController.selectedProjectId?.value; - if (projectId != null) { + final projectId = projectController.selectedProjectId.value; + if (projectId.isNotEmpty) { dailyTaskPlaningController.fetchTaskData(projectId); } // Reactive fetch on project ID change - final selectedProject = projectController.selectedProjectId; - if (selectedProject != null) { - ever( - selectedProject, - (newProjectId) { - if (newProjectId != null) { - dailyTaskPlaningController.fetchTaskData(newProjectId); - } - }, - ); - } + ever( + projectController.selectedProjectId, + (newProjectId) { + if (newProjectId.isNotEmpty) { + dailyTaskPlaningController.fetchTaskData(newProjectId); + } + }, + ); } @override @@ -128,8 +125,8 @@ class _DailyTaskPlaningScreenState extends State borderRadius: BorderRadius.circular(24), onTap: () async { final projectId = - projectController.selectedProjectId?.value; - if (projectId != null) { + projectController.selectedProjectId.value; + if (projectId.isNotEmpty) { try { await dailyTaskPlaningController .fetchTaskData(projectId); @@ -430,7 +427,8 @@ class _DailyTaskPlaningScreenState extends State onPressed: () { final pendingTask = (planned - completed) - .clamp(0, planned).toInt(); + .clamp(0, planned) + .toInt(); showModalBottomSheet( context: context,