Materialize options iterable to list in optionsViewBuilder

Avoids repeated iteration of the lazy .where().take() iterable on each
call to .length and .elementAt() in ListView.builder.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Doug Borg
2026-02-07 22:50:01 -07:00
committed by Doug Borg
parent 26c85df7e8
commit ef6fc1c9c8

View File

@@ -143,6 +143,7 @@ class _NSITagValueFieldState extends State<NSITagValueField> {
AutocompleteOnSelected<String> onSelected,
Iterable<String> options,
) {
final optionList = options.toList(growable: false);
return Align(
alignment: Alignment.topLeft,
child: Material(
@@ -153,9 +154,9 @@ class _NSITagValueFieldState extends State<NSITagValueField> {
child: ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: options.length,
itemCount: optionList.length,
itemBuilder: (context, index) {
final option = options.elementAt(index);
final option = optionList[index];
return ListTile(
dense: true,
title: Text(option, style: const TextStyle(fontSize: 14)),