gpt4 book ai didi

flutter - 如何将从 flutter 的多选小部件中选择的值保存到列表中

转载 作者:行者123 更新时间:2023-12-03 03:38:38 25 4
gpt4 key购买 nike

我在flutter项目中使用了这个flutter包“multiselect”来从下拉列表中选择多个数据。

List _fines;

MultiSelect(
autovalidate: false,
titleText: "Fine list",
validator: (value) {
if (value == null) {
return 'Please select one or more option(s)';
}
},
errorText: 'Please select one or more option(s)',
dataSource: [
{"display": "Fine No 1", "index": 1, "value": 5000},
{"display": "Fine no 2", "index": 2, "value": 2500},
{"display": "Fine no 3", "index": 3, "value": 1000},
{"display": "Fine no 4", "index": 4, "value": 500}
],
textField: 'display',
valueField: 'index',
filterable: true,
required: true,
value: null,
onSaved: (value) {
setState(() {
_fines = value;
});

})

我无法将数据保存到列表中。在on保存后,它说_fines list为空。谢谢你的时间。

最佳答案

您可以使用change回调函数作为MultiSelect小部件的参数来获取最后选择的值

List<int> selectedValues = [];

MultiSelect(
autovalidate: false,
titleText: "title",
validator: (value) {
if (value == null) {
return 'Please select one or more option(s)';
}
},
errorText: 'Please select one or more option(s)',
dataSource: [
{
"display": "Australia",
"value": 1,
},
{
"display": "Canada",
"value": 2,
},
{
"display": "India",
"value": 3,
},
{
"display": "United States",
"value": 4,
}
],
textField: 'display',
valueField: 'value',
filterable: true,
required: true,
value: null,
change: (values){
selectedValues = values;
print(selectedValues);
},
),

关于flutter - 如何将从 flutter 的多选小部件中选择的值保存到列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58919598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com