I'm using Flutter's Autocomplete but I would like to have it display above the TextField. Is this possible?
Here's the base setup:
Autocomplete<String>(
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') {
return const Iterable<String>.empty();
}
if (textEditingValue.text.contains('...')) {
return widget.myBloc.names
.where((String option) {
return option.contains(
textEditingValue.text.toLowerCase());
});
} else {
return const Iterable<String>.empty();
}
},
onSelected: (String selection) {
log('selection -> $selection');
},
optionsMaxHeight: 40,
fieldViewBuilder: (context, controller, focusNode,
onEditingComplete) {
return TextField();
}
)
I figured it out, but you're not gonna like the answer...
In the Flutter library, on line 367 of the RawAutocomplete implementation, they hardcoded its alignment to track the bottom left of the TextField. I was able to circumvent this only after copying their entire implementation, and doing the following:
targetAnchor: Alignment.topLeftfollowerAnchor: Alignment.bottomLeftOptionViewsBuilder wherever you decide to implement it, shown here in the material Autocomplete implementation, change to alignment: Alignment.bottomLeft.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With