- Implemented ContactProfileResponse and related models for handling contact details. - Created ContactTagResponse and ContactTag models for managing contact tags. - Added DirectoryCommentResponse and DirectoryComment models for comment management. - Developed DirectoryFilterBottomSheet for filtering contacts. - Introduced OrganizationListModel for organization data handling. - Updated routes to include DirectoryMainScreen. - Enhanced DashboardScreen to navigate to the new directory page. - Created ContactDetailScreen for displaying detailed contact information. - Developed DirectoryMainScreen for managing and displaying contacts. - Added dependencies for font_awesome_flutter and flutter_html in pubspec.yaml.
491 lines
21 KiB
Dart
491 lines
21 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:marco/controller/task_planing/report_task_controller.dart';
|
|
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
|
|
import 'package:marco/helpers/widgets/my_button.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';
|
|
|
|
class ReportTaskBottomSheet extends StatefulWidget {
|
|
final Map<String, dynamic> taskData;
|
|
final VoidCallback? onReportSuccess;
|
|
const ReportTaskBottomSheet({
|
|
super.key,
|
|
required this.taskData,
|
|
this.onReportSuccess,
|
|
});
|
|
|
|
@override
|
|
State<ReportTaskBottomSheet> createState() => _ReportTaskBottomSheetState();
|
|
}
|
|
|
|
class _ReportTaskBottomSheetState extends State<ReportTaskBottomSheet>
|
|
with UIMixin {
|
|
late final ReportTaskController controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// Initialize the controller with a unique tag (optional)
|
|
controller = Get.put(ReportTaskController(),
|
|
tag: widget.taskData['taskId'] ?? UniqueKey().toString());
|
|
|
|
final taskData = widget.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'] ?? '';
|
|
controller.basicValidator.getController('completed_work')?.clear();
|
|
controller.basicValidator.getController('comment')?.clear();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
|
|
),
|
|
child: SingleChildScrollView(
|
|
padding: EdgeInsets.only(
|
|
bottom: MediaQuery.of(context).viewInsets.bottom + 24,
|
|
left: 24,
|
|
right: 24,
|
|
top: 12,
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// Drag handle
|
|
Container(
|
|
width: 40,
|
|
height: 4,
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey.shade400,
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
GetBuilder<ReportTaskController>(
|
|
tag: widget.taskData['taskId'] ?? '',
|
|
init: controller,
|
|
builder: (_) {
|
|
return Form(
|
|
key: controller.basicValidator.formKey,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Center(
|
|
child: MyText.titleMedium(
|
|
"Report Task",
|
|
fontWeight: 600,
|
|
),
|
|
),
|
|
MySpacing.height(16),
|
|
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()} "
|
|
"of ${widget.taskData['pendingWork'] ?? '-'} Pending"),
|
|
Row(
|
|
children: [
|
|
Icon(Icons.work_outline,
|
|
size: 18, color: Colors.grey[700]),
|
|
MySpacing.width(8),
|
|
MyText.titleSmall(
|
|
"Completed Work:",
|
|
fontWeight: 600,
|
|
),
|
|
],
|
|
),
|
|
MySpacing.height(8),
|
|
TextFormField(
|
|
validator: (value) {
|
|
if (value == null || value.trim().isEmpty) {
|
|
return 'Please enter completed work';
|
|
}
|
|
final completed = int.tryParse(value.trim());
|
|
final pending = widget.taskData['pendingWork'] ?? 0;
|
|
|
|
if (completed == null) {
|
|
return 'Enter a valid number';
|
|
}
|
|
|
|
if (completed > pending) {
|
|
return 'Completed work cannot exceed pending work $pending';
|
|
}
|
|
|
|
return null;
|
|
},
|
|
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),
|
|
Row(
|
|
children: [
|
|
Icon(Icons.comment_outlined,
|
|
size: 18, color: Colors.grey[700]),
|
|
MySpacing.width(8),
|
|
MyText.titleSmall(
|
|
"Comment:",
|
|
fontWeight: 600,
|
|
),
|
|
],
|
|
),
|
|
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),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(Icons.camera_alt_outlined,
|
|
size: 18, color: Colors.grey[700]),
|
|
MySpacing.width(8),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
MyText.titleSmall("Attach Photos:",
|
|
fontWeight: 600),
|
|
MySpacing.height(12),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Obx(() {
|
|
final images = controller.selectedImages;
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
if (images.isEmpty)
|
|
Container(
|
|
height: 70,
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(
|
|
color: Colors.grey.shade300, width: 2),
|
|
color: Colors.grey.shade100,
|
|
),
|
|
child: Center(
|
|
child: Icon(Icons.photo_camera_outlined,
|
|
size: 48, color: Colors.grey.shade400),
|
|
),
|
|
)
|
|
else
|
|
SizedBox(
|
|
height: 70,
|
|
child: ListView.separated(
|
|
scrollDirection: Axis.horizontal,
|
|
itemCount: images.length,
|
|
separatorBuilder: (_, __) =>
|
|
MySpacing.width(12),
|
|
itemBuilder: (context, index) {
|
|
final file = images[index];
|
|
return Stack(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
showDialog(
|
|
context: context,
|
|
builder: (_) => Dialog(
|
|
child: InteractiveViewer(
|
|
child: Image.file(file),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
child: ClipRRect(
|
|
borderRadius:
|
|
BorderRadius.circular(12),
|
|
child: Image.file(
|
|
file,
|
|
height: 70,
|
|
width: 70,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
Positioned(
|
|
top: 4,
|
|
right: 4,
|
|
child: GestureDetector(
|
|
onTap: () => controller
|
|
.removeImageAt(index),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.black54,
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Icon(Icons.close,
|
|
size: 20,
|
|
color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
MySpacing.height(16),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: MyButton.outlined(
|
|
onPressed: () => controller.pickImages(
|
|
fromCamera: true),
|
|
padding: MySpacing.xy(12, 10),
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.camera_alt,
|
|
size: 16,
|
|
color: Colors.blueAccent),
|
|
MySpacing.width(6),
|
|
MyText.bodySmall('Capture',
|
|
color: Colors.blueAccent),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
MySpacing.width(12),
|
|
Expanded(
|
|
child: MyButton.outlined(
|
|
onPressed: () => controller.pickImages(
|
|
fromCamera: false),
|
|
padding: MySpacing.xy(12, 10),
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.upload_file,
|
|
size: 16,
|
|
color: Colors.blueAccent),
|
|
MySpacing.width(6),
|
|
MyText.bodySmall('Upload',
|
|
color: Colors.blueAccent),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: OutlinedButton.icon(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
icon: const Icon(Icons.close, color: Colors.red, size: 18),
|
|
label: MyText.bodyMedium(
|
|
"Cancel",
|
|
color: Colors.red,
|
|
fontWeight: 600,
|
|
),
|
|
style: OutlinedButton.styleFrom(
|
|
side: const BorderSide(color: Colors.red),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: Obx(() {
|
|
final isLoading =
|
|
controller.reportStatus.value == ApiStatus.loading;
|
|
|
|
return ElevatedButton.icon(
|
|
onPressed: isLoading
|
|
? null
|
|
: () async {
|
|
if (controller.basicValidator.validateForm()) {
|
|
final success = 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(),
|
|
images: controller.selectedImages,
|
|
);
|
|
if (success && widget.onReportSuccess != null) {
|
|
widget.onReportSuccess!();
|
|
}
|
|
}
|
|
},
|
|
icon: isLoading
|
|
? const SizedBox(
|
|
height: 16,
|
|
width: 16,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
|
),
|
|
)
|
|
: const Icon(Icons.check_circle_outline,
|
|
color: Colors.white, size: 18),
|
|
label: isLoading
|
|
? const SizedBox.shrink()
|
|
: MyText.bodyMedium(
|
|
"Report",
|
|
color: Colors.white,
|
|
fontWeight: 600,
|
|
),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.indigo,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
],
|
|
),
|
|
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget buildRow(String label, String? value) {
|
|
IconData icon;
|
|
switch (label) {
|
|
case "Assigned Date":
|
|
icon = Icons.calendar_today_outlined;
|
|
break;
|
|
case "Assigned By":
|
|
icon = Icons.person_outline;
|
|
break;
|
|
case "Work Area":
|
|
icon = Icons.place_outlined;
|
|
break;
|
|
case "Activity":
|
|
icon = Icons.run_circle_outlined;
|
|
break;
|
|
case "Team Size":
|
|
icon = Icons.group_outlined;
|
|
break;
|
|
case "Assigned":
|
|
icon = Icons.assignment_turned_in_outlined;
|
|
break;
|
|
default:
|
|
icon = Icons.info_outline;
|
|
}
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 16),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(icon, size: 18, color: Colors.grey[700]),
|
|
MySpacing.width(8),
|
|
MyText.titleSmall(
|
|
"$label:",
|
|
fontWeight: 600,
|
|
),
|
|
MySpacing.width(12),
|
|
Expanded(
|
|
child: MyText.bodyMedium(value?.isNotEmpty == true ? value! : "-"),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|