added multiselect bottom sheet in assign task bottom sheet form
This commit is contained in:
parent
f73643b391
commit
79c0ef3f65
@ -15,8 +15,10 @@ import 'package:marco/helpers/widgets/tenant/organization_selector.dart';
|
|||||||
import 'package:marco/helpers/widgets/tenant/service_selector.dart';
|
import 'package:marco/helpers/widgets/tenant/service_selector.dart';
|
||||||
import 'package:marco/model/attendance/organization_per_project_list_model.dart';
|
import 'package:marco/model/attendance/organization_per_project_list_model.dart';
|
||||||
import 'package:marco/model/tenant/tenant_services_model.dart';
|
import 'package:marco/model/tenant/tenant_services_model.dart';
|
||||||
|
|
||||||
|
// Added imports for employee selection
|
||||||
import 'package:marco/model/employees/employee_model.dart';
|
import 'package:marco/model/employees/employee_model.dart';
|
||||||
import 'package:marco/model/employees/multiple_select_role_bottomsheet.dart';
|
import 'package:marco/model/employees/multiple_select_bottomsheet.dart';
|
||||||
|
|
||||||
class AssignTaskBottomSheet extends StatefulWidget {
|
class AssignTaskBottomSheet extends StatefulWidget {
|
||||||
final String workLocation;
|
final String workLocation;
|
||||||
@ -48,6 +50,8 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
final DailyTaskPlanningController controller = Get.find();
|
final DailyTaskPlanningController controller = Get.find();
|
||||||
final ProjectController projectController = Get.find();
|
final ProjectController projectController = Get.find();
|
||||||
|
|
||||||
|
final OrganizationController orgController =
|
||||||
|
Get.put(OrganizationController());
|
||||||
final OrganizationController orgController =
|
final OrganizationController orgController =
|
||||||
Get.put(OrganizationController());
|
Get.put(OrganizationController());
|
||||||
final ServiceController serviceController = Get.put(ServiceController());
|
final ServiceController serviceController = Get.put(ServiceController());
|
||||||
@ -85,10 +89,8 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
serviceId: selectedService?.id,
|
serviceId: selectedService?.id,
|
||||||
organizationId: selectedOrganization?.id,
|
organizationId: selectedOrganization?.id,
|
||||||
);
|
);
|
||||||
await controller.fetchTaskData(
|
await controller.fetchTaskData(selectedProjectId,
|
||||||
selectedProjectId,
|
serviceId: selectedService?.id);
|
||||||
serviceId: selectedService?.id,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -145,10 +147,13 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
_infoRow(Icons.location_on, "Work Location",
|
_infoRow(Icons.location_on, "Work Location",
|
||||||
"${widget.buildingName} > ${widget.floorName} > ${widget.workAreaName} > ${widget.activityName}"),
|
"${widget.buildingName} > ${widget.floorName} > ${widget.workAreaName} > ${widget.activityName}"),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
|
||||||
|
// Pending Task Info
|
||||||
_infoRow(
|
_infoRow(
|
||||||
Icons.pending_actions, "Pending Task", "${widget.pendingTask}"),
|
Icons.pending_actions, "Pending Task", "${widget.pendingTask}"),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
|
||||||
|
// Role Selector (kept as-is)
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: _onRoleMenuPressed,
|
onTap: _onRoleMenuPressed,
|
||||||
child: Row(children: [
|
child: Row(children: [
|
||||||
@ -160,52 +165,52 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
|
|
||||||
MySpacing.height(8),
|
MySpacing.height(8),
|
||||||
|
|
||||||
/// TEAM SELECT BOX
|
// -------------------------------
|
||||||
|
// Employee selector (REPLACED)
|
||||||
|
// -------------------------------
|
||||||
|
// We show a button-like container (with border) that opens the reusable
|
||||||
|
// EmployeeSelectionBottomSheet. Selected employees are reflected using
|
||||||
|
// existing controller.uploadingStates & controller.selectedEmployees.
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: _openEmployeeSelectionSheet,
|
onTap: _openEmployeeSelectionSheet,
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: Colors.grey.shade300),
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(6),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.group, color: Colors.black54),
|
const Icon(Icons.group, color: Colors.black54),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
|
Expanded(
|
||||||
// Expanded name area
|
child: Obx(() {
|
||||||
Expanded(
|
final count = controller.selectedEmployees.length;
|
||||||
child: Obx(() {
|
if (count == 0) {
|
||||||
final count = controller.selectedEmployees.length;
|
return MyText("Select team members",
|
||||||
if (count == 0) {
|
color: Colors.grey.shade700);
|
||||||
return MyText(
|
}
|
||||||
"Select team members",
|
// show summary text when there are selected employees
|
||||||
color: Colors.grey.shade700,
|
final names = controller.selectedEmployees
|
||||||
maxLines: 1,
|
.map((e) => e.name)
|
||||||
overflow: TextOverflow.ellipsis,
|
.join(", ");
|
||||||
);
|
return Text(
|
||||||
}
|
names,
|
||||||
|
maxLines: 2,
|
||||||
final names = controller.selectedEmployees
|
overflow: TextOverflow.ellipsis,
|
||||||
.map((e) => e.name)
|
style: const TextStyle(fontSize: 14),
|
||||||
.join(", ");
|
);
|
||||||
|
}),
|
||||||
return Text(
|
),
|
||||||
names,
|
const SizedBox(width: 8),
|
||||||
maxLines: 2,
|
const Icon(Icons.arrow_drop_down, color: Colors.grey),
|
||||||
overflow: TextOverflow.ellipsis,
|
],
|
||||||
style: const TextStyle(fontSize: 14),
|
),
|
||||||
);
|
),
|
||||||
}),
|
|
||||||
),
|
|
||||||
|
|
||||||
const Icon(Icons.arrow_drop_down, color: Colors.grey),
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
),
|
),
|
||||||
|
|
||||||
MySpacing.height(8),
|
MySpacing.height(8),
|
||||||
|
|
||||||
|
// Selected Employees Chips (keeps existing behavior)
|
||||||
_buildSelectedEmployees(),
|
_buildSelectedEmployees(),
|
||||||
MySpacing.height(8),
|
MySpacing.height(8),
|
||||||
|
|
||||||
@ -233,6 +238,8 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onRoleMenuPressed() {
|
void _onRoleMenuPressed() {
|
||||||
|
final RenderBox overlay =
|
||||||
|
Overlay.of(context).context.findRenderObject() as RenderBox;
|
||||||
final RenderBox overlay =
|
final RenderBox overlay =
|
||||||
Overlay.of(context).context.findRenderObject() as RenderBox;
|
Overlay.of(context).context.findRenderObject() as RenderBox;
|
||||||
final Size screenSize = overlay.size;
|
final Size screenSize = overlay.size;
|
||||||
@ -255,13 +262,13 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null) {
|
if (value != null)
|
||||||
selectedRoleId = value == 'all' ? null : value;
|
controller.onRoleSelected(value == 'all' ? null : value);
|
||||||
controller.onRoleSelected(selectedRoleId);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removed old inline employee list; selection handled by bottom sheet.
|
||||||
|
|
||||||
Widget _buildSelectedEmployees() {
|
Widget _buildSelectedEmployees() {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
if (controller.selectedEmployees.isEmpty) return Container();
|
if (controller.selectedEmployees.isEmpty) return Container();
|
||||||
@ -307,15 +314,16 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: hintText,
|
hintText: hintText,
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(6)),
|
||||||
borderRadius: BorderRadius.circular(6),
|
|
||||||
),
|
|
||||||
contentPadding:
|
contentPadding:
|
||||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
),
|
),
|
||||||
validator: (value) => this
|
validator: (value) => this
|
||||||
.controller
|
.controller
|
||||||
.formFieldValidator(value, fieldType: validatorType),
|
.formFieldValidator(value, fieldType: validatorType),
|
||||||
|
validator: (value) => this
|
||||||
|
.controller
|
||||||
|
.formFieldValidator(value, fieldType: validatorType),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -334,16 +342,11 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
text: TextSpan(
|
text: TextSpan(
|
||||||
children: [
|
children: [
|
||||||
WidgetSpan(
|
WidgetSpan(
|
||||||
child: MyText.titleMedium(
|
child: MyText.titleMedium("$title: ",
|
||||||
"$title: ",
|
fontWeight: 600, color: Colors.black),
|
||||||
fontWeight: 600,
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: value,
|
text: value, style: const TextStyle(color: Colors.black)),
|
||||||
style: const TextStyle(color: Colors.black),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -354,41 +357,46 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _openEmployeeSelectionSheet() async {
|
Future<void> _openEmployeeSelectionSheet() async {
|
||||||
|
// Open the existing EmployeeSelectionBottomSheet
|
||||||
final result = await showModalBottomSheet<List<EmployeeModel>>(
|
final result = await showModalBottomSheet<List<EmployeeModel>>(
|
||||||
context: context,
|
context: context,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
shape: const RoundedRectangleBorder(
|
shape: const RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||||
),
|
),
|
||||||
builder: (context) {
|
builder: (context) => EmployeeSelectionBottomSheet(
|
||||||
return DraggableScrollableSheet(
|
initiallySelected: controller.selectedEmployees.toList(),
|
||||||
expand: false,
|
multipleSelection: true,
|
||||||
initialChildSize: 0.85,
|
title: 'Select Team Members',
|
||||||
minChildSize: 0.6,
|
),
|
||||||
maxChildSize: 1.0,
|
|
||||||
builder: (_, scrollController) {
|
|
||||||
return Container(
|
|
||||||
decoration: const BoxDecoration(
|
|
||||||
color: Colors.white,
|
|
||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
|
||||||
),
|
|
||||||
child: MultipleSelectRoleBottomSheet(
|
|
||||||
projectId: selectedProjectId!,
|
|
||||||
organizationId: selectedOrganization?.id,
|
|
||||||
serviceId: selectedService?.id,
|
|
||||||
roleId: selectedRoleId,
|
|
||||||
initiallySelected: controller.selectedEmployees.toList(),
|
|
||||||
scrollController: scrollController,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result != null) {
|
if (result == null) return;
|
||||||
controller.selectedEmployees
|
|
||||||
.assignAll(result); // RxList updates UI automatically
|
// Merge returned employees into controller.uploadingStates & controller.selectedEmployees
|
||||||
|
// 1) Reset all uploadingStates to false, then set true for selected
|
||||||
|
controller.uploadingStates.forEach((key, rx) {
|
||||||
|
rx.value = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (final emp in result) {
|
||||||
|
final idStr = emp.id.toString();
|
||||||
|
if (controller.uploadingStates.containsKey(idStr)) {
|
||||||
|
controller.uploadingStates[idStr]?.value = true;
|
||||||
|
} else {
|
||||||
|
// if uploadingStates doesn't have the id yet, add it (safe fallback)
|
||||||
|
controller.uploadingStates[idStr] = RxBool(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) Update selectedEmployees list in controller
|
||||||
|
controller.selectedEmployees.assignAll(result);
|
||||||
|
|
||||||
|
// 3) Call controller helper (keeps existing behavior)
|
||||||
|
try {
|
||||||
|
controller.updateSelectedEmployees();
|
||||||
|
} catch (_) {
|
||||||
|
// If controller does not implement updateSelectedEmployees, ignore.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,20 +405,18 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
|
|
||||||
if (selectedTeam.isEmpty) {
|
if (selectedTeam.isEmpty) {
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Team Required",
|
title: "Team Required",
|
||||||
message: "Please select at least one team member",
|
message: "Please select at least one team member",
|
||||||
type: SnackbarType.error,
|
type: SnackbarType.error);
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final target = double.tryParse(targetController.text.trim());
|
final target = double.tryParse(targetController.text.trim());
|
||||||
if (target == null || target <= 0) {
|
if (target == null || target <= 0) {
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Invalid Input",
|
title: "Invalid Input",
|
||||||
message: "Please enter a valid target number",
|
message: "Please enter a valid target number",
|
||||||
type: SnackbarType.error,
|
type: SnackbarType.error);
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,10 +432,9 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
final description = descriptionController.text.trim();
|
final description = descriptionController.text.trim();
|
||||||
if (description.isEmpty) {
|
if (description.isEmpty) {
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Description Required",
|
title: "Description Required",
|
||||||
message: "Please enter a description",
|
message: "Please enter a description",
|
||||||
type: SnackbarType.error,
|
type: SnackbarType.error);
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user