marco.pms.mobileapp/lib/view/taskPlaning/report_task_screen.dart
Vaibhav Surve 3a449441fa feat: Enhance project and task management features
- Added clearProjects method in ProjectController to reset project states.
- Updated fetchProjects and updateSelectedProject methods for better state management.
- Enhanced ReportTaskController to support image uploads with base64 encoding.
- Modified ApiService to handle image data in report and comment tasks.
- Integrated ProjectController in AuthService to fetch projects upon login.
- Updated LocalStorage to clear selectedProjectId on logout.
- Introduced ImageViewerDialog for displaying images in a dialog.
- Enhanced CommentTaskBottomSheet and ReportTaskBottomSheet to support image attachments.
- Improved AttendanceScreen to handle project selection and data fetching more robustly.
- Refactored EmployeesScreen to manage employee data based on project selection.
- Updated Layout to handle project selection and display appropriate messages.
- Enhanced DailyProgressReportScreen and DailyTaskPlaningScreen to reactively fetch task data based on project changes.
- Added photo_view dependency for improved image handling.
2025-06-12 17:28:06 +05:30

270 lines
10 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_lucide/flutter_lucide.dart';
import 'package:get/get.dart';
import 'package:marco/controller/task_planing/report_task_controller.dart';
import 'package:marco/helpers/theme/app_theme.dart';
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
import 'package:marco/helpers/utils/my_shadow.dart';
import 'package:marco/helpers/widgets/my_breadcrumb.dart';
import 'package:marco/helpers/widgets/my_breadcrumb_item.dart';
import 'package:marco/helpers/widgets/my_button.dart';
import 'package:marco/helpers/widgets/my_card.dart';
import 'package:marco/helpers/widgets/my_flex.dart';
import 'package:marco/helpers/widgets/my_flex_item.dart';
import 'package:marco/helpers/widgets/my_spacing.dart';
import 'package:marco/helpers/widgets/my_text.dart';
import 'package:marco/helpers/widgets/my_text_style.dart';
import 'package:marco/view/layouts/layout.dart';
class ReportTaskScreen extends StatefulWidget {
const ReportTaskScreen({super.key});
@override
State<ReportTaskScreen> createState() => _ReportTaskScreenState();
}
class _ReportTaskScreenState extends State<ReportTaskScreen> with UIMixin {
final ReportTaskController controller = Get.put(ReportTaskController());
@override
Widget build(BuildContext context) {
final taskData = Get.arguments as Map<String, dynamic>;
print("Task Data: $taskData");
controller.basicValidator.getController('assigned_date')?.text =
taskData['assignedOn'] ?? '';
controller.basicValidator.getController('assigned_by')?.text =
taskData['assignedBy'] ?? '';
controller.basicValidator.getController('work_area')?.text =
taskData['location'] ?? '';
controller.basicValidator.getController('activity')?.text =
taskData['activity'] ?? '';
controller.basicValidator.getController('team_size')?.text =
taskData['teamSize'].toString();
controller.basicValidator.getController('assigned')?.text =
taskData['assigned'] ?? '';
controller.basicValidator.getController('task_id')?.text =
taskData['taskId'] ?? '';
return Layout(
child: GetBuilder<ReportTaskController>(
init: controller,
tag: 'report_task_controller',
builder: (controller) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: MySpacing.x(flexSpacing),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MyText.titleMedium("Report Task",
fontSize: 18, fontWeight: 600),
MyBreadcrumb(
children: [
MyBreadcrumbItem(name: 'Daily Progress Report'),
MyBreadcrumbItem(name: 'Report Task'),
],
),
],
),
),
MySpacing.height(flexSpacing),
Padding(
padding: MySpacing.x(flexSpacing / 2),
child: MyFlex(
children: [
MyFlexItem(sizes: "lg-8 md-12", child: detail()),
],
),
),
],
);
},
),
);
}
Widget detail() {
return Form(
key: controller.basicValidator.formKey,
child: MyCard.bordered(
borderRadiusAll: 4,
border: Border.all(color: Colors.grey.withOpacity(0.2)),
shadow: MyShadow(elevation: 1, position: MyShadowPosition.bottom),
paddingAll: 24,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(LucideIcons.server, size: 16),
MySpacing.width(12),
MyText.titleMedium("General", fontWeight: 600),
],
),
MySpacing.height(24),
// Static fields
buildRow(
"Assigned Date",
controller.basicValidator
.getController('assigned_date')
?.text
.trim()),
buildRow(
"Assigned By",
controller.basicValidator
.getController('assigned_by')
?.text
.trim()),
buildRow(
"Work Area",
controller.basicValidator
.getController('work_area')
?.text
.trim()),
buildRow(
"Activity",
controller.basicValidator
.getController('activity')
?.text
.trim()),
buildRow(
"Team Size",
controller.basicValidator
.getController('team_size')
?.text
.trim()),
buildRow(
"Assigned",
controller.basicValidator
.getController('assigned')
?.text
.trim()),
// Input fields
MyText.labelMedium("Completed Work"),
MySpacing.height(8),
TextFormField(
validator:
controller.basicValidator.getValidation('completed_work'),
controller:
controller.basicValidator.getController('completed_work'),
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: "eg: 10",
hintStyle: MyTextStyle.bodySmall(xMuted: true),
border: outlineInputBorder,
enabledBorder: outlineInputBorder,
focusedBorder: focusedInputBorder,
contentPadding: MySpacing.all(16),
isCollapsed: true,
floatingLabelBehavior: FloatingLabelBehavior.never,
),
),
MySpacing.height(24),
MyText.labelMedium("Comment"),
MySpacing.height(8),
TextFormField(
validator: controller.basicValidator.getValidation('comment'),
controller: controller.basicValidator.getController('comment'),
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: "eg: Work done successfully",
hintStyle: MyTextStyle.bodySmall(xMuted: true),
border: outlineInputBorder,
enabledBorder: outlineInputBorder,
focusedBorder: focusedInputBorder,
contentPadding: MySpacing.all(16),
isCollapsed: true,
floatingLabelBehavior: FloatingLabelBehavior.never,
),
),
MySpacing.height(24),
// Buttons
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
MyButton.text(
onPressed: () => Get.back(),
padding: MySpacing.xy(20, 16),
splashColor: contentTheme.secondary.withValues(alpha: 0.1),
child: MyText.bodySmall('Cancel'),
),
MySpacing.width(12),
MyButton(
onPressed: controller.reportStatus.value == ApiStatus.loading
? null
: () async {
if (controller.basicValidator.validateForm()) {
await controller.reportTask(
projectId: controller.basicValidator
.getController('task_id')
?.text ??
'',
comment: controller.basicValidator
.getController('comment')
?.text ??
'',
completedTask: int.tryParse(controller
.basicValidator
.getController('completed_work')
?.text ??
'') ??
0,
checklist: [],
reportedDate: DateTime.now(),
);
}
},
elevation: 0,
padding: MySpacing.xy(20, 16),
backgroundColor: contentTheme.primary,
borderRadiusAll: AppStyle.buttonRadius.medium,
child: Obx(() {
if (controller.reportStatus.value == ApiStatus.loading) {
return SizedBox(
height: 16,
width: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
contentTheme.onPrimary),
),
);
} else {
return MyText.bodySmall(
'Save',
color: contentTheme.onPrimary,
);
}
}),
),
],
),
],
),
),
);
}
Widget buildRow(String label, String? value) {
print("Label: $label, Value: $value");
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MyText.labelMedium("$label:"),
MySpacing.width(12),
Expanded(
child: MyText.bodyMedium(value?.isNotEmpty == true ? value! : "-"),
),
],
),
);
}
}