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

View File

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