upadted with select enployee sheet
This commit is contained in:
parent
abe1f44fb4
commit
6a2d16a2b2
@ -15,10 +15,8 @@ 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_bottomsheet.dart';
|
import 'package:marco/model/employees/multiple_select_role_bottomsheet.dart';
|
||||||
|
|
||||||
class AssignTaskBottomSheet extends StatefulWidget {
|
class AssignTaskBottomSheet extends StatefulWidget {
|
||||||
final String workLocation;
|
final String workLocation;
|
||||||
@ -87,8 +85,10 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
serviceId: selectedService?.id,
|
serviceId: selectedService?.id,
|
||||||
organizationId: selectedOrganization?.id,
|
organizationId: selectedOrganization?.id,
|
||||||
);
|
);
|
||||||
await controller.fetchTaskData(selectedProjectId,
|
await controller.fetchTaskData(
|
||||||
serviceId: selectedService?.id);
|
selectedProjectId,
|
||||||
|
serviceId: selectedService?.id,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -145,13 +145,10 @@ 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: [
|
||||||
@ -163,12 +160,7 @@ 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(
|
||||||
@ -178,37 +170,44 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
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(
|
|
||||||
child: Obx(() {
|
// Expanded name area
|
||||||
final count = controller.selectedEmployees.length;
|
Expanded(
|
||||||
if (count == 0) {
|
child: Obx(() {
|
||||||
return MyText("Select team members",
|
final count = controller.selectedEmployees.length;
|
||||||
color: Colors.grey.shade700);
|
if (count == 0) {
|
||||||
}
|
return MyText(
|
||||||
// show summary text when there are selected employees
|
"Select team members",
|
||||||
final names = controller.selectedEmployees
|
color: Colors.grey.shade700,
|
||||||
.map((e) => e.name)
|
maxLines: 1,
|
||||||
.join(", ");
|
overflow: TextOverflow.ellipsis,
|
||||||
return Text(
|
);
|
||||||
names,
|
}
|
||||||
maxLines: 2,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
final names = controller.selectedEmployees
|
||||||
style: const TextStyle(fontSize: 14),
|
.map((e) => e.name)
|
||||||
);
|
.join(", ");
|
||||||
}),
|
|
||||||
),
|
return Text(
|
||||||
const SizedBox(width: 8),
|
names,
|
||||||
const Icon(Icons.arrow_drop_down, color: Colors.grey),
|
maxLines: 2,
|
||||||
],
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
style: const TextStyle(fontSize: 14),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
|
||||||
|
const Icon(Icons.arrow_drop_down, color: Colors.grey),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
MySpacing.height(8),
|
|
||||||
|
|
||||||
// Selected Employees Chips (keeps existing behavior)
|
MySpacing.height(8),
|
||||||
_buildSelectedEmployees(),
|
_buildSelectedEmployees(),
|
||||||
MySpacing.height(8),
|
MySpacing.height(8),
|
||||||
|
|
||||||
@ -258,13 +257,13 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null)
|
if (value != null) {
|
||||||
controller.onRoleSelected(value == 'all' ? null : value);
|
selectedRoleId = 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();
|
||||||
@ -310,7 +309,9 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: hintText,
|
hintText: hintText,
|
||||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(6)),
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
contentPadding:
|
contentPadding:
|
||||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||||
),
|
),
|
||||||
@ -335,11 +336,16 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
text: TextSpan(
|
text: TextSpan(
|
||||||
children: [
|
children: [
|
||||||
WidgetSpan(
|
WidgetSpan(
|
||||||
child: MyText.titleMedium("$title: ",
|
child: MyText.titleMedium(
|
||||||
fontWeight: 600, color: Colors.black),
|
"$title: ",
|
||||||
|
fontWeight: 600,
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: value, style: const TextStyle(color: Colors.black)),
|
text: value,
|
||||||
|
style: const TextStyle(color: Colors.black),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -350,46 +356,42 @@ 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) => EmployeeSelectionBottomSheet(
|
builder: (context) {
|
||||||
initiallySelected: controller.selectedEmployees.toList(),
|
return DraggableScrollableSheet(
|
||||||
multipleSelection: true,
|
expand: false,
|
||||||
title: 'Select Team Members',
|
initialChildSize: 0.85,
|
||||||
),
|
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) return;
|
if (result != null) {
|
||||||
|
controller.selectedEmployees.assignAll(result);
|
||||||
// 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();
|
controller.updateSelectedEmployees();
|
||||||
} catch (_) {
|
|
||||||
// If controller does not implement updateSelectedEmployees, ignore.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,18 +400,20 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,9 +429,10 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -200,6 +200,26 @@ class _EmployeeSelectionBottomSheetState
|
|||||||
final emp = results[index];
|
final emp = results[index];
|
||||||
final isSelected = _selectedEmployees.contains(emp);
|
final isSelected = _selectedEmployees.contains(emp);
|
||||||
|
|
||||||
|
Widget trailingWidget;
|
||||||
|
|
||||||
|
if (widget.multipleSelection) {
|
||||||
|
// Multiple selection → normal checkbox
|
||||||
|
trailingWidget = Checkbox(
|
||||||
|
value: isSelected,
|
||||||
|
onChanged: (_) => _toggleEmployee(emp),
|
||||||
|
fillColor: MaterialStateProperty.resolveWith<Color>(
|
||||||
|
(states) => states.contains(MaterialState.selected)
|
||||||
|
? Colors.blueAccent
|
||||||
|
: Colors.white,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Single selection → check circle
|
||||||
|
trailingWidget = isSelected
|
||||||
|
? const Icon(Icons.check_circle, color: Colors.blueAccent)
|
||||||
|
: const Icon(Icons.circle_outlined, color: Colors.grey);
|
||||||
|
}
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: CircleAvatar(
|
leading: CircleAvatar(
|
||||||
backgroundColor: Colors.blueAccent,
|
backgroundColor: Colors.blueAccent,
|
||||||
@ -211,15 +231,7 @@ class _EmployeeSelectionBottomSheetState
|
|||||||
),
|
),
|
||||||
title: Text('${emp.firstName} ${emp.lastName}'),
|
title: Text('${emp.firstName} ${emp.lastName}'),
|
||||||
subtitle: Text(emp.email),
|
subtitle: Text(emp.email),
|
||||||
trailing: Checkbox(
|
trailing: trailingWidget,
|
||||||
value: isSelected,
|
|
||||||
onChanged: (_) => _toggleEmployee(emp),
|
|
||||||
fillColor: MaterialStateProperty.resolveWith<Color>(
|
|
||||||
(states) => states.contains(MaterialState.selected)
|
|
||||||
? Colors.blueAccent
|
|
||||||
: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () => _toggleEmployee(emp),
|
onTap: () => _toggleEmployee(emp),
|
||||||
contentPadding:
|
contentPadding:
|
||||||
const EdgeInsets.symmetric(horizontal: 0, vertical: 4),
|
const EdgeInsets.symmetric(horizontal: 0, vertical: 4),
|
||||||
|
|||||||
@ -59,10 +59,12 @@ class _MultipleSelectRoleBottomSheetState
|
|||||||
List<EmployeeModel> employees = controller.employees.toList();
|
List<EmployeeModel> employees = controller.employees.toList();
|
||||||
|
|
||||||
if (widget.roleId != null && widget.roleId!.isNotEmpty) {
|
if (widget.roleId != null && widget.roleId!.isNotEmpty) {
|
||||||
employees =
|
employees = employees
|
||||||
employees.where((emp) => emp.jobRoleID == widget.roleId).toList();
|
.where((emp) => emp.jobRoleID == widget.roleId)
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Selected first
|
||||||
employees.sort((a, b) {
|
employees.sort((a, b) {
|
||||||
final aSel = _selected.any((e) => e.id == a.id) ? 0 : 1;
|
final aSel = _selected.any((e) => e.id == a.id) ? 0 : 1;
|
||||||
final bSel = _selected.any((e) => e.id == b.id) ? 0 : 1;
|
final bSel = _selected.any((e) => e.id == b.id) ? 0 : 1;
|
||||||
@ -91,6 +93,7 @@ class _MultipleSelectRoleBottomSheetState
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Selected on top
|
||||||
_filtered.sort((a, b) {
|
_filtered.sort((a, b) {
|
||||||
final aSel = _selected.any((e) => e.id == a.id) ? 0 : 1;
|
final aSel = _selected.any((e) => e.id == a.id) ? 0 : 1;
|
||||||
final bSel = _selected.any((e) => e.id == b.id) ? 0 : 1;
|
final bSel = _selected.any((e) => e.id == b.id) ? 0 : 1;
|
||||||
@ -108,8 +111,8 @@ class _MultipleSelectRoleBottomSheetState
|
|||||||
_selected.add(emp);
|
_selected.add(emp);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Single selection → return immediately
|
_selected.assignAll([emp]);
|
||||||
Get.back(result: [emp]);
|
Get.back(result: _selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onSearch(_searchController.text.trim());
|
_onSearch(_searchController.text.trim());
|
||||||
@ -148,17 +151,49 @@ class _MultipleSelectRoleBottomSheetState
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// ⭐ NEW — Chips showing selected employees
|
||||||
|
Widget _selectedChips() {
|
||||||
|
return Obx(() {
|
||||||
|
if (_selected.isEmpty) return const SizedBox();
|
||||||
|
|
||||||
|
return Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: _selected.map((emp) {
|
||||||
|
return Chip(
|
||||||
|
label: Text(emp.name),
|
||||||
|
deleteIcon: const Icon(Icons.close),
|
||||||
|
onDeleted: () {
|
||||||
|
_selected.remove(emp);
|
||||||
|
_onSearch(_searchController.text.trim());
|
||||||
|
},
|
||||||
|
backgroundColor: Colors.blue.shade50,
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BaseBottomSheet(
|
return BaseBottomSheet(
|
||||||
title: widget.title,
|
title: widget.title,
|
||||||
onCancel: () => Get.back(),
|
onCancel: () => Get.back(),
|
||||||
onSubmit: () => Get.back(result: _selected.toList()), // Return plain list
|
onSubmit: () => Get.back(result: _selected),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: MediaQuery.of(context).size.height * 0.55,
|
height: MediaQuery.of(context).size.height * 0.55,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
_searchBar(),
|
_searchBar(),
|
||||||
|
|
||||||
|
/// ⭐ Chips shown right below search bar
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
|
child: _selectedChips(),
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 6),
|
||||||
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Obx(() {
|
child: Obx(() {
|
||||||
if (_isLoading.value) {
|
if (_isLoading.value) {
|
||||||
@ -191,15 +226,6 @@ class _MultipleSelectRoleBottomSheetState
|
|||||||
trailing: Checkbox(
|
trailing: Checkbox(
|
||||||
value: isSelected,
|
value: isSelected,
|
||||||
onChanged: (_) => _onTap(emp),
|
onChanged: (_) => _onTap(emp),
|
||||||
fillColor:
|
|
||||||
MaterialStateProperty.resolveWith<Color>((states) {
|
|
||||||
if (states.contains(MaterialState.selected)) {
|
|
||||||
return Colors.blueAccent;
|
|
||||||
}
|
|
||||||
return Colors.white;
|
|
||||||
}),
|
|
||||||
checkColor: Colors.white,
|
|
||||||
side: const BorderSide(color: Colors.grey),
|
|
||||||
),
|
),
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
horizontal: 4,
|
horizontal: 4,
|
||||||
|
|||||||
@ -208,7 +208,7 @@ class _PaymentRequestBottomSheetState extends State<_PaymentRequestBottomSheet>
|
|||||||
? null
|
? null
|
||||||
: "Enter valid amount"),
|
: "Enter valid amount"),
|
||||||
_gap(),
|
_gap(),
|
||||||
_buildPayeeAutocompleteField(),
|
_buildPayeeField(),
|
||||||
_gap(),
|
_gap(),
|
||||||
_buildDropdown(
|
_buildDropdown(
|
||||||
"Currency",
|
"Currency",
|
||||||
@ -353,67 +353,27 @@ class _PaymentRequestBottomSheetState extends State<_PaymentRequestBottomSheet>
|
|||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
SectionTitle(
|
const SectionTitle(
|
||||||
icon: Icons.person_outline, title: "Payee", requiredField: true),
|
icon: Icons.person_outline,
|
||||||
const SizedBox(height: 6),
|
title: "Payee",
|
||||||
Autocomplete<String>(
|
requiredField: true,
|
||||||
optionsBuilder: (textEditingValue) {
|
),
|
||||||
final query = textEditingValue.text.toLowerCase();
|
MySpacing.height(6),
|
||||||
return query.isEmpty
|
GestureDetector(
|
||||||
? const Iterable<String>.empty()
|
onTap: _showPayeeSelector,
|
||||||
: controller.payees
|
child: TileContainer(
|
||||||
.where((p) => p.toLowerCase().contains(query));
|
child: Row(
|
||||||
},
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
displayStringForOption: (option) => option,
|
children: [
|
||||||
fieldViewBuilder:
|
Expanded(
|
||||||
(context, fieldController, focusNode, onFieldSubmitted) {
|
child: Obx(() => Text(
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
controller.selectedPayee.value?.name ?? "Select Payee",
|
||||||
if (fieldController.text != controller.selectedPayee.value) {
|
style: const TextStyle(fontSize: 15),
|
||||||
fieldController.text = controller.selectedPayee.value;
|
overflow: TextOverflow.ellipsis,
|
||||||
fieldController.selection = TextSelection.fromPosition(
|
)),
|
||||||
TextPosition(offset: fieldController.text.length));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return TextFormField(
|
|
||||||
controller: fieldController,
|
|
||||||
focusNode: focusNode,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: "Type or select payee",
|
|
||||||
filled: true,
|
|
||||||
fillColor: Colors.grey.shade100,
|
|
||||||
contentPadding:
|
|
||||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
|
||||||
border: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
|
||||||
),
|
),
|
||||||
),
|
const Icon(Icons.arrow_drop_down, size: 22),
|
||||||
validator: (v) =>
|
],
|
||||||
v == null || v.trim().isEmpty ? "Please enter payee" : null,
|
|
||||||
onChanged: (val) => controller.selectedPayee.value = val,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onSelected: (selection) => controller.selectedPayee.value = selection,
|
|
||||||
optionsViewBuilder: (context, onSelected, options) => Material(
|
|
||||||
color: Colors.white,
|
|
||||||
elevation: 4,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
child: ConstrainedBox(
|
|
||||||
constraints: const BoxConstraints(maxHeight: 200, minWidth: 300),
|
|
||||||
child: ListView.builder(
|
|
||||||
padding: EdgeInsets.zero,
|
|
||||||
itemCount: options.length,
|
|
||||||
itemBuilder: (_, index) => InkWell(
|
|
||||||
onTap: () => onSelected(options.elementAt(index)),
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: 10, horizontal: 12),
|
|
||||||
child: Text(options.elementAt(index),
|
|
||||||
style: const TextStyle(fontSize: 14)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user