flutter - 如何在 Flutter 中清除输入文本
问题描述
当用户单击 X 图标时,我正在尝试清除文本,当我单击它时我的搜索结果为空,但我的输入文本仍然存在,所以如果我能就如何获得任何帮助或建议,我将不胜感激也可以清除输入的文字。
Expanded(
flex: 8,
child: GestureDetector(
onTap: () {},
child: TextFormField(
autofocus: true,
enabled: true,
onChanged: (va) {
filterSearchResult(va, model);
},
decoration: InputDecoration(
floatingLabelBehavior:
FloatingLabelBehavior.never,
border: InputBorder.none,
hintStyle: TextStyle(
color:
Theme.of(context).secondaryHeaderColor)),
),
)),
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
items.clear();
itemList.clear();
});
},
child: Image.asset(
"assets/icons/cancel.png",
color: Theme.of(context).secondaryHeaderColor,
height: 30,
)),
),
解决方案
我使用 TextEditingController myController 并将 myController.text 设置为 null
推荐阅读
- c# - 更改 ItemsSource 集合中的属性时如何重绘 ItemsControl ItemsPanel?
- javascript - 在右拆分中显示页面
- swift - 我可以在两个单独的视图控制器上获得相同的 firebase 数据吗?
- html - VBA Web Scrape按类名类型不匹配错误获取元素
- quad - 使用 scipy.quad 集成的 Bessel 函数不起作用
- python - 我已安装 nlopt,但收到消息:没有名为“nlopt”的模块
- android - android如何排列视图?
- c# - SQL Server 查询并转换为 Linq
- java - PendingIntent 多任务
- javascript - ReasonML 访问 JS 记录字段