Reputation: 2192
Flutter provides an Autocomplete widget. If I enter "abc"
instead of selecting one of the suggestions, then how can I get this text "abc"
?
Upvotes: 4
Views: 1276
Reputation: 63569
You can create another variable to hold the input String inside state class like String? _inputString;
and update value inside optionsBuilder
class _AutocompleteBasicExampleState extends State<AutocompleteBasicExample> {
String? _inputString;
@override
Widget build(BuildContext context) {
return Autocomplete<String>(
optionsBuilder: (TextEditingValue textEditingValue) {
setState(() {
_inputString = textEditingValue.text;
});
Upvotes: 3