TextFieldAutoCompleteState<T> constructor

TextFieldAutoCompleteState<T>(
  1. List<T> suggestions,
  2. StringCallback? textChanged,
  3. StringCallback? textSubmitted,
  4. ValueSetter<bool>? onFocusChanged,
  5. InputEventCallback<T>? itemSubmitted,
  6. AutoCompleteOverlayItemBuilder<T>? itemBuilder,
  7. Comparator<T>? itemSorter,
  8. Filter<T>? itemFilter,
  9. int suggestionsAmount,
  10. bool submitOnSuggestionTap,
  11. bool clearOnSubmit,
  12. int minLength,
  13. List<TextInputFormatter>? inputFormatters,
  14. TextCapitalization textCapitalization,
  15. InputDecoration decoration,
  16. TextStyle? style,
  17. TextInputType keyboardType,
  18. TextInputAction textInputAction,
  19. TextEditingController? controller,
  20. FocusNode? focusNode,
)

Implementation

TextFieldAutoCompleteState(
    this.suggestions,
    this.textChanged,
    this.textSubmitted,
    this.onFocusChanged,
    this.itemSubmitted,
    this.itemBuilder,
    this.itemSorter,
    this.itemFilter,
    this.suggestionsAmount,
    this.submitOnSuggestionTap,
    this.clearOnSubmit,
    this.minLength,
    this.inputFormatters,
    this.textCapitalization,
    this.decoration,
    this.style,
    this.keyboardType,
    this.textInputAction,
    this.controller,
    this.focusNode) {
  textField = new TextField(
    inputFormatters: inputFormatters,
    textCapitalization: textCapitalization,
    decoration: decoration,
    style: style,
    keyboardType: keyboardType,
    focusNode: focusNode ?? new FocusNode(),
    controller: controller ?? new TextEditingController(),
    textInputAction: textInputAction,
    onChanged: (newText) {
      currentText = newText;
      updateOverlay(newText);

      if (textChanged != null) {
        textChanged!(newText);
      }
    },
    onTap: () {
      updateOverlay(currentText);
    },
    onSubmitted: (submittedText) =>
        triggerSubmitted(submittedText: submittedText),
  );

  if (this.controller != null && this.controller!.text != '') {
    currentText = this.controller!.text;
  }

  textField!.focusNode!.addListener(() {
    if (onFocusChanged != null) {
      onFocusChanged!(textField!.focusNode!.hasFocus);
    }

    if (!textField!.focusNode!.hasFocus) {
      filteredSuggestions = [];
      updateOverlay();
    } else if (!(currentText == "" || currentText == '')) {
      updateOverlay(currentText);
    }
  });
}