static void TwoPicker(context, {
required List<dynamic> list,
required Function onConfirm,
List<int>? selecteds
}){
print(list);
Picker picker = Picker(
adapter: PickerDataAdapter(
pickerdata: list,
isArray: true
),
changeToFirst: false,
textAlign: TextAlign.left,
cancelText: "取消",
confirmText: "确定",
cancelTextStyle: const TextStyle(color: Colors.grey),
confirmTextStyle: TextStyle(color: ColorConst.mainColor),
selecteds: selecteds,
itemExtent: 40,
textStyle: const TextStyle(color: Colors.black, fontSize: 16),
// selectedTextStyle: TextStyle(color: Colors.red),
columnPadding: const EdgeInsets.all(5),
onConfirm: (Picker picker, List value) {
// print(value.toString());
// print(picker.getSelectedValues());
if(list[0] == null || value[0] == null){
onConfirm(null);
}else{
onConfirm(list[value[0]]);
}
});
picker.showModal(context);
}
其中list是这样的数据,[[{name:'',value:''},{name:'',value:''}],[{name:'',value:''}]]
效果是
我要怎么使用name字段作为显示呀?
查阅源码,发现在Picker.dart中有个_parseArrayPickerDataItem方法,此方式是设置PickerItem的。将其拿出来改写,如下:
然后在调用处,编写以下代码
isArray必须设置为true,因为在别处会用到。