flutter_typeahead
flutter_typeahead copied to clipboard
suggestion list is slow when the list of suggestions contains more than hundred entries
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 You should open a PR for this. It's clearly a very obvious optimisation the maintainers should merge.