updateOverlay method

void updateOverlay([
  1. String? query
])

Implementation

void updateOverlay([String? query]) {
  if (listSuggestionsEntry == null && filteredSuggestions != null) {
    final Size textFieldSize = (context.findRenderObject() as RenderBox).size;
    final width = textFieldSize.width;
    final height = textFieldSize.height;
    listSuggestionsEntry = OverlayEntry(builder: (context) {
      return Positioned(
          width: width,
          child: CompositedTransformFollower(
              link: _layerLink,
              showWhenUnlinked: false,
              offset: Offset(0.0, height),
              child: SizedBox(
                  width: width,
                  child: Card(
                      child: new Column(
                    children: filteredSuggestions!.map((suggestion) {
                      return Row(children: [
                        Expanded(
                            child: InkWell(
                                child: itemBuilder!(context, suggestion),
                                onTap: () {
                                  if (!this.mounted) return;
                                  setState(() {
                                    if (submitOnSuggestionTap) {
                                      String newText = suggestion.toString();
                                      textField!.controller!.text = newText;
                                      if (unFocusOnItemSubmitted) {
                                        textField!.focusNode!.unfocus();
                                      }
                                      itemSubmitted!(suggestion);
                                      if (clearOnSubmit) {
                                        clear();
                                      }
                                    } else {
                                      String newText = suggestion.toString();
                                      textField!.controller!.text = newText;
                                      textChanged!(newText);
                                    }
                                  });
                                }))
                      ]);
                    }).toList(),
                  )))));
    });
    Overlay.of(context)!.insert(listSuggestionsEntry!);
  }

  filteredSuggestions = getSuggestions(
      suggestions, itemSorter, itemFilter, suggestionsAmount, query);

  listSuggestionsEntry?.markNeedsBuild();
}