【发布时间】:2020-09-26 04:22:51
【问题描述】:
以下代码提供了用于搜索的 TextField,但是,我希望在右侧清除“X”,以便用户可以清除搜索而无需退格。
TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.all(16.0),
prefixIcon: Icon(
Icons.search,
color: Colors.white,
),
//Placeholder potential X for clearing search
/*suffix: IconButton(
icon: Icon(Icons.clear), onPressed: () => TODO),*/
hintText: 'Search by name',
hintStyle: TextStyle(
fontWeight: FontWeight.w500, color: Colors.white)),
onChanged: (string) {
setState(() {
filterAssets = assets
.where((test) => (test.name
.toLowerCase()
.contains(string.toLowerCase())))
.toList();
});
},
),
【问题讨论】: