Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 获取数组抖动时的复选框id_Flutter_Dart_Flutter Layout - Fatal编程技术网

Flutter 获取数组抖动时的复选框id

Flutter 获取数组抖动时的复选框id,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我有一个复选框颤振,所以我需要从复选框中选择多个项目,我需要传递给一个函数作为数组如何做,我可以得到一个数据,而不是多个选择的项目 Container( width: double.infinity, height: 250, child: new ListView.builder( itemCount: service_type.length, itemBui

我有一个复选框颤振,所以我需要从复选框中选择多个项目,我需要传递给一个函数作为数组如何做,我可以得到一个数据,而不是多个选择的项目

Container(
            width: double.infinity,
            height: 250,
            child: new ListView.builder(
                itemCount: service_type.length,
                itemBuilder: (BuildContext context, int index){
                  return new CheckboxListTile(
                      value: inputs[index],
                      title: new Text(service_type[index].service_type_name),
                      controlAffinity: ListTileControlAffinity.leading,
                      onChanged:(bool val){
                        ItemChange(val, index);
                        setState(() {
                          selectedChecboxmenuid=service_type[index].service_type_id;
                          print(selectedChecboxmenuid);
                        });
                      }
                  );

                }
            ),
          )

您只需在名为
service\u type
的对象内创建一个名为
isSelected=false的新字段(不是列表,它应该在类内)

单击项目时,将特定对象的状态更改为
isSelected=true

Ex:

List<int> list = [];

    onChanged:(bool status){
                            ItemChange(val, index);
                            setState(() {
                              service_type[index].isSelected = status;
                              for(var service in service_type) {
                                   if(service.isSelected) {
                                      
                             list.add(service_type[index].service_type_id);
// now pass this list wherever you want
                                  }
                                }
                            });
                          }
List=[];
一旦更改:(布尔状态){
项目变更(val、索引);
设置状态(){
服务类型[索引].isSelected=状态;
for(服务类型中的var服务){
如果(选择服务){
list.add(服务类型[索引].service类型\u id);
//现在,将此列表传递到您想要的任何位置
}
}
});
}

现在我们知道了,从列表中选择了哪个项目,因此现在您可以迭代列表,并根据
isSelected
标志获取
service\u type\u id

很抱歉延迟回复,我可以检查数据,没有问题,但每次只发送一个值,我如何将2个数据从复选框传递给函数,这样我就可以像这样将值传递给api
[1,2]
@Jitesh mohite首先需要迭代名为service_type的列表,找到选中的复选框值,并将它们添加到新创建的列表中,最后,将其发送到Function,你能帮我提供一些示例代码@Jitesh mohite吗?请看修改后的代码