如何从颤动的选项列表中制作清单?

How to make checklist from a list of options in flutter?

示例数据:

  var electricianmulti = [
  new Multimodel(
      question: "What services are you looking for?",
      options: ["Complete wiring", "switches", "water motor", "MCB & fuse"],

  new Multimodel(
      question: "What time of the day do you prefer?",
      options: ["Early Morning", "Morning", "Afternoon", "Evening"],];
      

我正在从 listview.generate 中创建复选框,如下所示-

children: <Widget>[
                  ...List.generate(
                      electricianmulti[i].options.length,
                      (index) => Container(
                          padding: EdgeInsets.all(5),
                          margin: EdgeInsets.all(10),
                          child: CheckboxListTile(
                            // controlAffinity: ListTileControlAffinity.leading,
                            title: new Text(
                              electricianmulti[i].options[index].toString(),
                              style: optionstxt,
                            ),
                            value:isselected,
                            activeColor: Colors.blue,
                            checkColor: Colors.white,
                            onChanged: (bool value) {
                              setState(() {
                               isselected=value
                              });
                            },

这段代码的工作方式就像我点击任何一个框,所有的框都被选中。我尝试制作一个 bool 数组并根据 'i' 更新它,但它似乎也不起作用。我在这里做错了什么?

value: isselected

正在采用单个布尔值并将其分配给所有复选框。 将 isselected 更改为布尔值列表,然后使用

value: isselected[i];

同样在setState中,使用

isselected[i] = value;

确保选中的长度等于复选框的数量。