searchfield
searchfield copied to clipboard
suggestions not updating if inside a modal
Get.defaultDialog(
navigatorKey: navigatorKey,
onWillPop: () async {
setState(() {
selectedValue = null;
selectedTimeslot = null;
dateTimeSelected.value = "";
userSelected.value = "";
});
return true;
},
title: "Add a booking",
radius: 10.0,
content: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10),
width: 400,
child: Column(
children: [
const SizedBox(height: 10),
SearchField(
autofocus: true,
onSubmit: (query) {
setState(() {
searchText = query;
focus2.requestFocus();
performSearch(query);
filterSuggestions(searchText);
// keepDropdownOpen();
});
return "";
},
onSearchTextChanged: (query) {
setState(() {
searchText = query;
});
},
animationDuration: Duration.zero,
showEmpty: isLoading,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.length < 4) {
return '';
}
return null;
},
emptyWidget: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(24),
),
height: 250,
),
// key: const Key('searchfield'),
hint: 'Search suggestions',
itemHeight: 70,
scrollbarDecoration: ScrollbarDecoration(),
onTapOutside: (x) {},
suggestionStyle:
const TextStyle(fontSize: 20, color: Colors.black),
searchInputDecoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(24),
borderSide: const BorderSide(
width: 1,
color: Colors.grey,
style: BorderStyle.solid,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(24),
borderSide: const BorderSide(
width: 1,
color: Colors.black,
style: BorderStyle.solid,
),
),
fillColor: Colors.white,
contentPadding: const EdgeInsets.symmetric(horizontal: 20),
),
suggestions: filterSuggestions(searchText),
focusNode: focus2,
suggestionState: Suggestion.expand,
onSuggestionTap:
(SearchFieldListItem<Map<String, String>> x) {},
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: submitBooking,
child: const Text("Submit"),
)
],
),
),
),
);
}
List<SearchFieldListItem<Map<String, String>>> filterSuggestions(
String query,
) {
final filter = suggestions.where((element) {
final displayName = element['displayName']?.toLowerCase() ?? '';
final email = element['email']?.toLowerCase() ?? '';
return displayName.contains(query.toLowerCase()) ||
email.contains(query.toLowerCase());
}).toList();
return filter
.map(
(e) => SearchFieldListItem<Map<String, String>>(
e['email']!,
child: buildSearchChild(e['displayName']!, e['email']!),
),
)
.toList();
}
Hello @danilo1998271, Thanks for filing the issue, Can you please provide minimal and complete code sample which I can directly run without any additional package apart from the searchfield.
Thanks!
Provided that there has been no update on this issue from the author, We will assume that the issue no longer exists, If you are still encountering the issue please feel free to comment on this issue and we will reopen it.