I am trying to make a screen with filter, and a search buttons, but whenever i select a text field the screen start searching, even if i haven’t written anything yet, i am using a column with 2 textFields, none of them uses onChanged or onTap functions, after the textfields, there is a button, where i wanted to do the search, and after the button there’s a future builder, where the info is suposed to show.
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: ctrl1,
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
decoration: const InputDecoration(
border: OutlineInputBorder(),
fillColor: Colors.white,
labelText: 'filter1',
floatingLabelBehavior: FloatingLabelBehavior.always,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: ctrl2,
decoration: const InputDecoration(
border: OutlineInputBorder(),
fillColor: Colors.white,
labelText: 'filter2',
floatingLabelBehavior: FloatingLabelBehavior.always,
),
),
)
Whenever i tap or change any of the text fields, apparently the state updates, forcing the search. How can i stop the textfields from updating the state of the Screen when tapped or changed?
3
Answers
Show Your screen code, you need to set textformfield Above the searching function
Don’t use addListener on TextEditingController. Use onChanged option for search.
Bonus : Don’t forget to dispose your controllers to avoid memory leak.