update for tag should submit after space

This commit is contained in:
Manish 2025-11-25 13:18:15 +05:30
parent 24bfccfdf6
commit 28c1c36e07
2 changed files with 32 additions and 36 deletions

View File

@ -315,15 +315,31 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
height: 48,
child: TextField(
controller: tagCtrl,
onChanged: controller.filterSuggestions,
onChanged: (value) {
if (value.endsWith(" ") || value.endsWith(",")) {
final cleaned = value.trim().replaceAll(",", "");
if (cleaned.isNotEmpty) {
controller.addEnteredTag(cleaned);
}
tagCtrl.clear();
controller.clearSuggestions();
} else {
controller.filterSuggestions(value);
}
},
onSubmitted: (v) {
controller.addEnteredTag(v);
if (v.trim().isNotEmpty) {
controller.addEnteredTag(v.trim());
}
tagCtrl.clear();
controller.clearSuggestions();
},
decoration: _inputDecoration("Start typing to add tags"),
),
),
Obx(() => controller.filteredSuggestions.isEmpty
? const SizedBox.shrink()
: Container(
@ -353,7 +369,10 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
},
),
)),
MySpacing.height(8),
// TAG CHIPS
Obx(() => Wrap(
spacing: 8,
children: controller.enteredTags

View File

@ -48,9 +48,7 @@ class _EmployeeSelectionBottomSheetState
super.dispose();
}
// ------------------------------------------------------
// 🔥 Optimized debounce-based search
// ------------------------------------------------------
// SEARCH WITH DEBOUNCE
void _onSearchChanged(String query) {
_debounce?.cancel();
_debounce = Timer(const Duration(milliseconds: 300), () {
@ -68,29 +66,18 @@ class _EmployeeSelectionBottomSheetState
.toList();
// ------------------------------------------------------
// Auto-move selected employees to top
// REMOVED "MOVE SELECTED TO TOP"
// ------------------------------------------------------
results.sort((a, b) {
if (widget.multipleSelection) {
// Only move selected employees to top in multi-select
final aSel = _selectedEmployees.contains(a) ? 0 : 1;
final bSel = _selectedEmployees.contains(b) ? 0 : 1;
if (aSel != bSel) return aSel.compareTo(bSel);
}
// Otherwise, keep original order (or alphabetically if needed)
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
});
// Keeping alphabetical order only
results
.sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()));
_allResults.assignAll(results);
_isSearching.value = false;
}
// ------------------------------------------------------
// Handle tap & checkbox
// ------------------------------------------------------
// HANDLE TAP & CHECKBOX
void _toggleEmployee(EmployeeModel emp) {
if (widget.multipleSelection) {
if (_selectedEmployees.contains(emp)) {
@ -102,13 +89,11 @@ class _EmployeeSelectionBottomSheetState
_selectedEmployees.assignAll([emp]);
}
// Re-sort list after each toggle
// Refresh list but do NOT reorder selected
_performSearch(_searchController.text.trim());
}
// ------------------------------------------------------
// Submit selection
// ------------------------------------------------------
// SUBMIT SELECTION
void _handleSubmit() {
if (widget.multipleSelection) {
Navigator.of(context).pop(_selectedEmployees.toList());
@ -118,9 +103,7 @@ class _EmployeeSelectionBottomSheetState
}
}
// ------------------------------------------------------
// Search bar widget
// ------------------------------------------------------
// SEARCH BAR
Widget _searchBar() => Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: TextField(
@ -150,9 +133,7 @@ class _EmployeeSelectionBottomSheetState
),
);
// ------------------------------------------------------
// Employee list (optimized)
// ------------------------------------------------------
// EMPLOYEE LIST
Widget _employeeList() => Expanded(
child: Obx(() {
final results = _allResults;
@ -167,7 +148,6 @@ class _EmployeeSelectionBottomSheetState
Widget trailingWidget;
if (widget.multipleSelection) {
// Multiple selection normal checkbox
trailingWidget = Checkbox(
value: isSelected,
onChanged: (_) => _toggleEmployee(emp),
@ -178,7 +158,6 @@ class _EmployeeSelectionBottomSheetState
),
);
} else {
// Single selection check circle
trailingWidget = isSelected
? const Icon(Icons.check_circle, color: Colors.blueAccent)
: const Icon(Icons.circle_outlined, color: Colors.grey);
@ -205,9 +184,7 @@ class _EmployeeSelectionBottomSheetState
}),
);
// ------------------------------------------------------
// Build bottom sheet
// ------------------------------------------------------
// BUILD BOTTOM SHEET
@override
Widget build(BuildContext context) {
return BaseBottomSheet(