flutter_typeahead icon indicating copy to clipboard operation
flutter_typeahead copied to clipboard

suggestion list is slow when the list of suggestions contains more than hundred entries

Open pndaza opened this issue 3 years ago • 1 comments

Performance drop occurs when the list of suggestions contains more than hundred entries. #117 Typeahead does not use List.builderconstructor for suggestion list. so more entry, more slow. any plan to use List.builder constructor instead of children property.

comment from source

/// Typically, the list of suggestions should not contain more than 4 or 5 entries.

current

Widget createSuggestionsWidget() {
    Widget child = ListView(
      padding: EdgeInsets.zero,
      primary: false,
      shrinkWrap: true,
      controller: _scrollController,
      reverse: widget.suggestionsBox!.direction == AxisDirection.down
          ? false
          : true, // reverses the list to start at the bottom
      children: this._suggestions!.map((T suggestion) {
        return InkWell(
          child: widget.itemBuilder!(context, suggestion),
          onTap: () {
            widget.onSuggestionSelected!(suggestion);
          },
        );
      }).toList(),
    );

    if (widget.decoration!.hasScrollbar) {
      child = Scrollbar(
        controller: _scrollController,
        child: child,
      );
    }

    return child;
  }

suggetstion

Widget createSuggestionsWidget() {
    // switch to ListView.builder for better performance with huge suggestion entries
    Widget child = ListView.builder(
        padding: EdgeInsets.zero,
        primary: false,
        shrinkWrap: true,
        controller: _scrollController,
        reverse: widget.suggestionsBox!.direction == AxisDirection.down
            ? false
            : true, // reverses the list to start at the bottom
        itemCount: _suggestions?.length,
        itemBuilder: (_, index) {
          return InkWell(
            child: widget.itemBuilder!(
                context, _suggestions?.elementAt(index) as T),
            onTap: () {
              widget.onSuggestionSelected!(_suggestions?.elementAt(index) as T);
            },
          );
        });

    if (widget.decoration?.hasScrollbar == true) {
      child = Scrollbar(
        controller: _scrollController,
        child: child,
      );
    }

    return child;
  }
}

pndaza avatar Jan 02 '22 12:01 pndaza

@pndaza You should open a PR for this. It's clearly a very obvious optimisation the maintainers should merge.

aaaaahaaaaa avatar Jul 24 '22 18:07 aaaaahaaaaa