Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

flutter clear textfield

//Initialize a controller inside your State class
TextEditingController _controller = TextEditingController();

//Set the _controller on you TextField
TextField(
  controller: _controller,
  //Rest of your code
)

//Clear the controller after pushing the new page
onPressed: () {
   Navigator.push(context, new MaterialPageRoute(
     builder: (context) => SearchPage(searchText: this.search.text)
   )).then((value) {
      //This makes sure the textfield is cleared after page is pushed.
      _controller.clear();
   });
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #flutter #clear #textfield
ADD COMMENT
Topic
Name
4+1 =