onSelectSuggestion method

void onSelectSuggestion(
  1. DropDownModel<T> value
)

Implementation

void onSelectSuggestion(DropDownModel<T> value) {
  if (selectedValues.map((el) => el.key).contains(value.key)) {
    selectedValues.removeWhere((el) => el.key == value.key);
  } else {
    selectedValues.add(value);
  }

  if (selectedValues.isNotEmpty) {
    searchTextController.text = selectedValues.first.text;
    if (selectedValues.length > 1) {
      searchTextController.text += " (+${selectedValues.length - 1})";
    }
  } else {
    searchTextController.text = "";
  }

  setValidationError = null;
  if (onOptionSelected != null) {
    onOptionSelected!(selectedValues);
  }
  notifyListeners();
}