Closed tezine closed 2 years ago
I know it's been a month, but this might help. Use a global key assigned to the autocomplete textfield, e.g. _autoKey. Use updateSuggestions, like this: _autoKey.currentState.updateSuggestions(List suggestions);
can you give complete code sample having same issues
AutoCompleteTextField autoComplete;
Widget build(Build context)
set autoComplete
variable to AutoCompleteTextField
instanceautoComplete.updateSuggestions(suggestions)
method whenever suggestions
array is updatedThat worked for me.
con respuesta muy pobres le voy a pasa la solución definitiva, hay que pensar como no conocemos el código
GlobalKey<AutoCompleteTextFieldState<String>> keyAutoCompleteText = new GlobalKey();
la llave keyAutoCompleteText se declara al inicio del componete keyAutoCompleteText.currentState.updateSuggestions(listaPlaca);
en este caso de uso use un método obtenerListaPlaca() este me actualiza la información y ejecuto el
keyAutoCompleteText.currentState.updateSuggestions(listaPlaca);
ejemplo completo:
class InspeccionDiariaVehiculoForm extends StatefulWidget {
@override
InspeccionSstRcoFormState createState() => InspeccionSstRcoFormState();
}
class InspeccionSstRcoFormState extends State<InspeccionDiariaVehiculoForm> {
GlobalKey<AutoCompleteTextFieldState<String>> keyAutoCompleteText = new GlobalKey();
Future<List<String>> obtenerListaPlaca() async {
listaPlaca = await vehiculoPlacaDB.getDataList();
keyAutoCompleteText.currentState.updateSuggestions(listaPlaca);
}
}
Widget buildTextFielPlaca() {
return SimpleAutoCompleteTextField(
controller: controllerPlaca,
suggestions: listaPlaca,
decoration: InputDecoration(
labelText: "Placa",
),
key: keyAutoCompleteText,
onFocusChanged: (hasFocus) {},
textSubmitted: (text) {
//_controller_tipo_unidad.text = text;
},
clearOnSubmit: false,
);
}
This can be done, just update the suggestions list when the backend request is completed.
Hi, is it possible to use a dynamic suggestion list? The idea is to retrieve a suggestion list from the backend based on what's typed by the user, so whenever the text changes, a new list is filled with suggestions. I'm using Consumer and Provider, updating the suggestion list
onPointerDown
, and callingnotifyListeners
after the retrieval of new items, but they are not displayed as suggestions. Is there anyway to contour this issue?