updateSearchQuery method

List<MultiSelectItem<T>> updateSearchQuery(
  1. String? val,
  2. List<MultiSelectItem<T>> allItems
)

Accepts the search query, and the original list of items. If the search query is valid, return a filtered list, otherwise return the original list.

Implementation

List<MultiSelectItem<T>> updateSearchQuery(
    String? val, List<MultiSelectItem<T>> allItems) {
  if (val != null && val.trim().isNotEmpty) {
    List<MultiSelectItem<T>> filteredItems = [];
    for (var item in allItems) {
      if (item.label.toLowerCase().contains(val.toLowerCase())) {
        filteredItems.add(item);
      }
    }
    return filteredItems;
  } else {
    return allItems;
  }
}