updateOverlay method
Implementation
Future<void> updateOverlay(
{String? query, bool withoutFilter = false}) async {
if (!mounted) return;
$debugPrint(
"NoFilter $withoutFilter Focus ${focusNode.hasFocus}", "updateOverlay");
filteredItems = withoutFilter == true
? items
: await getItems(items, itemSorter, itemFilter, itemCount, query);
if (itemsOverlayEntry == null && mounted) {
final Size textFieldSize = (context.findRenderObject() as RenderBox).size;
final width = textFieldSize.width;
final height = textFieldSize.height;
itemsOverlayEntry = OverlayEntry(builder: (context) {
$debugPrint("Focus ${focusNode.hasFocus}", "OverlayEntry");
if (!focusNode.hasFocus) clearOverlay();
final listHeight = filteredItems.length > visibleCount
? (visibleCount * itemHeight).toDouble() + 6
: null;
return Positioned(
width: width,
child: CompositedTransformFollower(
link: _layerLink,
showWhenUnlinked: false,
offset: Offset(0.0, (height - 24).abs()),
child: SizedBox(
width: width,
height: listHeight,
child: Card(
child: Scrollbar(
child: ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: listHeight == null,
itemCount: filteredItems.length,
itemBuilder: (context, index) {
final item = filteredItems[index];
return Row(children: [
Expanded(
child: itemBuilder(
context,
item,
() => setState(() {
if (submitOnItemTap) {
String newText = item.toString();
controller.text = newText;
itemSubmitted(item);
focusNode.unfocus();
clearOverlay();
if (clearOnSubmit) clear();
} else {
String newText = item.toString();
controller.text = newText;
textChanged!(newText);
}
removeError();
}),
),
)
]);
},
),
),
),
),
),
);
});
Overlay.of(context)!.insert(itemsOverlayEntry!);
}
itemsOverlayEntry!.markNeedsBuild();
}