I have an InPutDecorator that looks liek this with Autocomplete:
// ********** Item Type Auto Compleate Start
InputDecorator(
decoration: const InputDecoration(
icon: Icon(Icons.style),
border: InputBorder.none,
),
child: Autocomplete<String>(
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') {
return itemTypeList;
}
return itemTypeList.where((String option) {
return option
.toLowerCase()
.contains(textEditingValue.text.toLowerCase());
});
}, fieldViewBuilder:
(context, controller, focusNode, onEditingComplete) {
itemTypeController = controller;
return Focus(
onFocusChange: (hasFocus) {
if (temperatureItemTypes
.contains(itemTypeController.text.trim())) {
//show temperature field
setState(() {
temperatureField = true;
});
} else {
setState(() {
temperatureField = false;
});
}
if (volumeItemTypes
.contains(itemTypeController.text.trim())) {
//show temperature field
setState(() {
volumeField = true;
});
} else {
setState(() {
volumeField = false;
});
}
},
child: TextFormField(
controller: controller,
focusNode: focusNode,
onEditingComplete: onEditingComplete,
decoration: const InputDecoration(
labelText: "Item type*",
hintText: 'What is the item?',
),
),
);
}),
),
For some reason the auto complete box is huge and extends off the screen to the right:
I tried looking at the Widget inspector and it seems like the autocomplete is breaking out of the constraints of the textFormField which is odd.
I also tried wrapping the auto complete in a container but flutter said it was redundant.
It looks like its a bug in Flutter, and I read through this stack overflow which was similar: Flutter 2.0 - Autocomplete widget goes out of screen from right side
BUthad trouble adapting their code to mine. I think we are approaching it slightly different and I am having trouble understanding.