search<K extends Object> method

void search<K extends Object>(
  1. K query, {
  2. required DropdownItemMatcher<K, T> matcher,
})

Search the loaded items that match the given query, and set the matched items to the dropdown menu. It would be marked as a history without modifying the original items.

Implementation

void search<K extends Object>(
  K query, {
  required DropdownItemMatcher<K, T> matcher,
}) {
  if (_currentHistory?.key == query) {
    return;
  }

  final old = _removeHistory(query);

  if (old != null) {
    _addHistory(query, old.items);
  } else {
    final matchedItems =
        _itemValues.where((item) => matcher(query, item)).toList();

    _addHistory(query, matchedItems);
  }

  rebuildMenu();
}