按下 Enter 后如何删除所选项目。这是我的代码
DropdownSearch<UserModel>(
selectedItem: name ?? null,
dropdownBuilder: (context, selectedItem) {
nama = selectedItem;
return Text(
"${nama ?? "${itemController.text ?? ''}"}",
// style: TextStyle(
// // fontSize: 20,
// color: Colors.black,
// ),
);
},
asyncItems:(filter) async {
if (ItemList != null) {
// print(UserModel.fromJsonList(serviceDataList));
print(ItemList);
return UserModel.fromJsonList(ItemList.where((user) => user['item_name'].toLowerCase().contains(filter.toLowerCase())).toList());
}
return [];
}),
这是我的代码,我正在使用下拉搜索依赖项
您可以设置空值
selectedItem
,它将从drondownSearch中删除所选值。
示例代码
class Fs extends StatefulWidget {
const Fs({super.key});
@override
State<Fs> createState() => _FsState();
}
class _FsState extends State<Fs> {
String? _selectedItem;
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_selectedItem = null;
});
},
),
body: Column(
children: [
DropdownSearch<String>(
popupProps: PopupProps.menu(
showSelectedItems: true,
disabledItemFn: (String s) => s.startsWith('I'),
),
items: ["Brazil", "Italia (Disabled)", "Tunisia", 'Canada'],
dropdownDecoratorProps: DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
labelText: "Menu mode",
hintText: "country in menu mode",
),
),
onChanged: (String? data) {
setState(() {
_selectedItem = data;
});
},
selectedItem: _selectedItem,
)
],
),
);
}
}
您可以设置:
clearButtonProps: const ClearButtonProps(isVisible:true)
到下拉搜索。