flutter - Flutter:在MultiSelect中选定项目后未触发onSaved事件
问题描述
我正在使用官方的 Flutter Multiselect - flutter_multiselect: ^0.5.1 一切正常,但是在选择/取消选择并单击 MultiSelect 小部件中的保存按钮后未触发 onSaved() 事件。我只想在控制台中打印选中/取消选中的项目。
注意:我也试图通过 change() 事件,它只有在我们选择选项时才有效,在取消选择时无效。
帮我解决这个问题
示例代码:
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
),
alignment: Alignment.center,
child: new MultiSelect(
maxLength: 1,
maxLengthText: "",
autovalidate: false,
dataSource: countries,
textField: 'country_name',
valueField: 'country_id',
hintText: "Select Your Country",
initialValue: countryID,
value: countryID,
required: true,
validator: (value) {
if (value == null) {
return 'Please Select Country';
}
},
filterable: true,
change: (values) {
if (values != null) {
setState(() {
countryID = values.cast<String>();
getStatesByCountry();
});
}
//this event emitted while selecting option from multiselect
//not works on deselecting option from multiselect
},
onSaved: (value) {
debugPrint("on save event");
print(value);
//always not emitting
},
),
)
解决方案
我不知道它是正确的方法,但在我的情况下,只是清理了一个构建并重新安装了 packge 会在删除多选中的项目时发出 onchange 事件,没有其他方法对我有用
推荐阅读
- amazon-web-services - How aws step functions were implemented?
- javascript - Firestore update all documents in collections
- vbscript - Skip some text from line
- c - Embedded RTOS producer and consumer with many types of messages
- python - 多端口 pika 连接
- python - 使用 pdf url (pdf2image) 将 pdf 转换为图像
- powershell - 使用 Powershell 拉取 Microsoft AD 中的国家/地区列表
- java - 协议变量一致
- node.js - Enable compression in nodejs grpc server
- apache-spark - 在 Apache spark 中启动 master 时无法从类 io.netty.channel.socket.nio.NioServerSocketChannel 创建通道