Jemolah
Jemolah

Reputation: 2192

Flutter: How to obtain text entered from Autocomplete field instead of selecting a suggestion?

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

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

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

Related Questions