updateSuggestionList method

void updateSuggestionList(
  1. List<T> suggestions
)

show suggestions overlay with data source. if suggestions is empty

Implementation

void updateSuggestionList(List<T> suggestions) {
  if (suggestions.isEmpty) {
    hideAutoComplete();
    return;
  }

  _suggestionList = suggestions;
  if (_suggestionsEntry == null) {
    final Size childSize = (context.findRenderObject() as RenderBox).size;
    final width = childSize.width;
    final height = childSize.height;

    _suggestionsEntry = 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: Column(
                children: _suggestionList.map((T suggestion) {
                  return Row(
                    children: <Widget>[
                      Expanded(
                        child: InkWell(
                          child: widget.itemBuilder(context, suggestion),
                          onTap: () {
                            widget.onSelectedSuggestion?.call(suggestion);
                            if (widget.hideAfterSelection) {
                              hideAutoComplete();
                            }
                          },
                        ),
                      )
                    ],
                  );
                }).toList(),
              ),
            ),
          ),
        ),
      );
    });
    Overlay.of(context)!.insert(_suggestionsEntry!);
    _display = true;
  } else {
    _suggestionsEntry!.markNeedsBuild();
  }
}