feat: Refactor project ID handling and enhance CommentTaskBottomSheet integration #49

Merged
vaibhav.surve merged 1 commits from Vaibhav_Task-#515 into main 2025-06-23 10:04:14 +00:00
5 changed files with 108 additions and 49 deletions

View File

@ -53,7 +53,7 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
selectedProjectId = projectController.selectedProjectId?.value; selectedProjectId = projectController.selectedProjectId.value;
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
if (selectedProjectId != null) { if (selectedProjectId != null) {
@ -147,7 +147,6 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
child: _buildEmployeeList(), child: _buildEmployeeList(),
), ),
MySpacing.height(8), MySpacing.height(8),
Obx(() { Obx(() {
if (controller.selectedEmployees.isEmpty) return Container(); if (controller.selectedEmployees.isEmpty) return Container();
@ -179,7 +178,6 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
), ),
); );
}), }),
_buildTextField( _buildTextField(
icon: Icons.track_changes, icon: Icons.track_changes,
label: "Target for Today :", label: "Target for Today :",
@ -189,7 +187,6 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
validatorType: "target", validatorType: "target",
), ),
MySpacing.height(24), MySpacing.height(24),
_buildTextField( _buildTextField(
icon: Icons.description, icon: Icons.description,
label: "Description :", label: "Description :",
@ -199,7 +196,6 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
validatorType: "description", validatorType: "description",
), ),
MySpacing.height(24), MySpacing.height(24),
Row( Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [

View File

@ -12,15 +12,21 @@ import 'package:marco/helpers/widgets/my_team_model_sheet.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:marco/helpers/widgets/image_viewer_dialog.dart'; import 'package:marco/helpers/widgets/image_viewer_dialog.dart';
import 'dart:io'; import 'dart:io';
import 'package:marco/model/dailyTaskPlaning/create_task_botom_sheet.dart';
class CommentTaskBottomSheet extends StatefulWidget { class CommentTaskBottomSheet extends StatefulWidget {
final Map<String, dynamic> taskData; final Map<String, dynamic> taskData;
final VoidCallback? onCommentSuccess; final VoidCallback? onCommentSuccess;
final String taskDataId;
final String workAreaId;
final String activityId;
const CommentTaskBottomSheet({ const CommentTaskBottomSheet({
super.key, super.key,
required this.taskData, required this.taskData,
this.onCommentSuccess, this.onCommentSuccess,
required this.taskDataId,
required this.workAreaId,
required this.activityId,
}); });
@override @override
@ -128,17 +134,72 @@ class _CommentTaskBottomSheetState extends State<CommentTaskBottomSheet>
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Column(
mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
MyText.titleMedium( MySpacing.height(12),
"Comment Task", Row(
fontWeight: 600, mainAxisAlignment: MainAxisAlignment.center,
fontSize: 18, 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( buildRow(
"Assigned By", "Assigned By",
controller.basicValidator controller.basicValidator

View File

@ -72,6 +72,9 @@ class TaskActionButtons {
required BuildContext context, required BuildContext context,
required dynamic task, required dynamic task,
required VoidCallback refreshCallback, required VoidCallback refreshCallback,
required String parentTaskID,
required String activityId,
required String workAreaId,
}) { }) {
return OutlinedButton.icon( return OutlinedButton.icon(
icon: const Icon(Icons.comment, size: 18, color: Colors.blueAccent), icon: const Icon(Icons.comment, size: 18, color: Colors.blueAccent),
@ -82,7 +85,8 @@ class TaskActionButtons {
textStyle: const TextStyle(fontSize: 14), textStyle: const TextStyle(fontSize: 14),
), ),
onPressed: () { onPressed: () {
final taskData = _prepareTaskData(task: task, completed: task.completedTask.toInt()); final taskData =
_prepareTaskData(task: task, completed: task.completedTask.toInt());
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
@ -90,6 +94,9 @@ class TaskActionButtons {
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
builder: (_) => CommentTaskBottomSheet( builder: (_) => CommentTaskBottomSheet(
taskData: taskData, taskData: taskData,
taskDataId: parentTaskID,
workAreaId: workAreaId,
activityId: activityId,
onCommentSuccess: () { onCommentSuccess: () {
refreshCallback(); refreshCallback();
Navigator.of(context).pop(); Navigator.of(context).pop();

View File

@ -44,29 +44,23 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
void initState() { void initState() {
super.initState(); super.initState();
final initialProjectId = projectController.selectedProjectId?.value; final initialProjectId = projectController.selectedProjectId.value;
if (initialProjectId != null) { if (initialProjectId.isNotEmpty) {
dailyTaskController.selectedProjectId = initialProjectId; dailyTaskController.selectedProjectId = initialProjectId;
dailyTaskController.fetchTaskData(initialProjectId); dailyTaskController.fetchTaskData(initialProjectId);
} }
final selectedProjectIdRx = projectController.selectedProjectId; ever<String>(
if (selectedProjectIdRx != null) { projectController.selectedProjectId,
ever<String?>( (newProjectId) async {
selectedProjectIdRx, if (newProjectId.isNotEmpty &&
(newProjectId) async { newProjectId != dailyTaskController.selectedProjectId) {
if (newProjectId != null && dailyTaskController.selectedProjectId = newProjectId;
newProjectId != dailyTaskController.selectedProjectId) { await dailyTaskController.fetchTaskData(newProjectId);
dailyTaskController.selectedProjectId = newProjectId; dailyTaskController.update(['daily_progress_report_controller']);
await dailyTaskController.fetchTaskData(newProjectId); }
dailyTaskController.update(['daily_progress_report_controller']); },
} );
},
);
} else {
debugPrint(
"Warning: selectedProjectId is null, skipping listener setup.");
}
} }
@override @override
@ -486,6 +480,9 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
TaskActionButtons.commentButton( TaskActionButtons.commentButton(
context: context, context: context,
task: task, task: task,
parentTaskID: parentTaskID,
workAreaId: workAreaId.toString(),
activityId: activityId.toString(),
refreshCallback: _refreshData, refreshCallback: _refreshData,
), ),
], ],

View File

@ -33,23 +33,20 @@ class _DailyTaskPlaningScreenState extends State<DailyTaskPlaningScreen>
super.initState(); super.initState();
// Initial fetch if a project is already selected // Initial fetch if a project is already selected
final projectId = projectController.selectedProjectId?.value; final projectId = projectController.selectedProjectId.value;
if (projectId != null) { if (projectId.isNotEmpty) {
dailyTaskPlaningController.fetchTaskData(projectId); dailyTaskPlaningController.fetchTaskData(projectId);
} }
// Reactive fetch on project ID change // Reactive fetch on project ID change
final selectedProject = projectController.selectedProjectId; ever<String>(
if (selectedProject != null) { projectController.selectedProjectId,
ever<String?>( (newProjectId) {
selectedProject, if (newProjectId.isNotEmpty) {
(newProjectId) { dailyTaskPlaningController.fetchTaskData(newProjectId);
if (newProjectId != null) { }
dailyTaskPlaningController.fetchTaskData(newProjectId); },
} );
},
);
}
} }
@override @override
@ -128,8 +125,8 @@ class _DailyTaskPlaningScreenState extends State<DailyTaskPlaningScreen>
borderRadius: BorderRadius.circular(24), borderRadius: BorderRadius.circular(24),
onTap: () async { onTap: () async {
final projectId = final projectId =
projectController.selectedProjectId?.value; projectController.selectedProjectId.value;
if (projectId != null) { if (projectId.isNotEmpty) {
try { try {
await dailyTaskPlaningController await dailyTaskPlaningController
.fetchTaskData(projectId); .fetchTaskData(projectId);
@ -430,7 +427,8 @@ class _DailyTaskPlaningScreenState extends State<DailyTaskPlaningScreen>
onPressed: () { onPressed: () {
final pendingTask = final pendingTask =
(planned - completed) (planned - completed)
.clamp(0, planned).toInt(); .clamp(0, planned)
.toInt();
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,