Igor D
Igor D

Reputation: 168

Flutter: TextFormField does not submit on onSaved/onTap/onSubmitteed

I'm working on a searchbar in the appbar. this should display a search icon and when pressed, a text field and close icon. I got this working and functional.

the problem I'm facing now is that I cannot get the onfieldsubmitted to work.

I changed from textfield to formtextfield, but without success.

void _searchPressed() {
print('search pressed');
setState(() {
  if (this._searchIcon.icon == Icons.search) {
    this._searchIcon = new Icon(Icons.close);

    //this textformfield should print the value when on softkeyboard enter 
is pressed.
    this._appBarTitle = new TextFormField(
      controller: _filter,
      textInputAction: TextInputAction.done,
      //its about this part
      onFieldSubmitted: (String value){
        print(value + 'identifier');
      },
      decoration: new InputDecoration(
          prefixIcon: new Icon(Icons.search),
          hintText: 'Search for product...'
      ),
    );
  } else {
    this._searchIcon = new Icon(Icons.search);
    this._appBarTitle = new Text('uniMarkt');

    _filter.clear();
  }
});

}

I would like to see the value of the submitted text + "identifier" when the enter on the keyboard is pressed.

as of now, the value does get printed in the console, but not with a print statement in my code, which is weird!

Upvotes: 2

Views: 6917

Answers (1)

Reza Esfandiari
Reza Esfandiari

Reputation: 946

use onFieldSubmitted when using TextFormField

Upvotes: 9

Related Questions