我正在尝试制作一个带有过滤器和搜索按钮的屏幕,但是每当我选择一个文本字段时,屏幕就会开始搜索,即使我还没有写任何内容,我正在使用带有 2 个文本字段的列,其中没有一个使用 onChanged 或 onTap 函数,在文本字段之后,有一个按钮,我想在其中进行搜索,在按钮之后有一个未来的构建器,其中应该显示信息。
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,
),
),
)
每当我点击或更改任何文本字段时,显然状态都会更新,从而强制进行搜索。如何阻止文本字段在点击或更改时更新屏幕状态?
显示您的屏幕代码,您需要将textformfield设置在搜索功能上方