Flutter 复选框:如何一个接一个地划掉文本,而不是完全抖动

Flutter 复选框:如何一个接一个地划掉文本,而不是完全抖动,flutter,flutter-layout,Flutter,Flutter Layout,我有以下问题,我有一个复选框列表,如果我点击复选框,列表中包含的所有部分都会被划掉,但我希望特定的框划掉特定的文本行。这就是它的样子。如果我按下任何一个框,我所有的文字都会被划掉。 下面是(希望如此)相关的代码 body: SizedBox( height: 200, child: ListView.builder( itemCount: info.expandedVal

我有以下问题,我有一个复选框列表,如果我点击复选框,列表中包含的所有部分都会被划掉,但我希望特定的框划掉特定的文本行。这就是它的样子。如果我按下任何一个框,我所有的文字都会被划掉。

下面是(希望如此)相关的代码

                body: SizedBox(
              height: 200,
              child: ListView.builder(
                  itemCount: info.expandedValueData.length,
                  itemBuilder: (context, index) {
                    return CheckboxListTile(
                        title: Text(info.expandedValueData[index].title,
                            style: TextStyle(
                                decoration: info.completed
                                    ? TextDecoration.lineThrough
                                    : null)),
                        value: info.completed,
                        onChanged: (value) {
                          setState(() {
// Here you toggle the checked item state
                            infos.firstWhere(
                                    (currentInfo) => info == currentInfo)
                              ..completed = value;
                          });
                        });
                  }),
            ),
编辑所以我需要像这样添加布尔值吗

expandedValue(id: 2, completed: false, title: "funktionierende Elektrik"),
  expandedValue(id: 3, completed: false, title: "Sitze"),
  expandedValue(id: 4, completed: false, title: "Rest"),
我这样修改了它&在前面的代码中,我将info.completed部分编辑为info.expandedValueData[index]。completed,之后出现错误“布尔表达式不能为null”,无法解决此问题:

                        return CheckboxListTile(
                        title: Text(info.expandedValueData[index].title,
                            style: TextStyle(
                                decoration:
                                    info.expandedValueData[index].completed
                                        ? TextDecoration.lineThrough
                                        : null)),
                        value: info.expandedValueData[index].completed,
                        onChanged: (value) {
                          setState(() {
// Here you toggle the checked item state
                            infos.firstWhere(
                                (currentInfo) => info == currentInfo)
                              ..expandedValueData[index].completed = value;
                          });
                        });

从您提供的代码中可以看出,我认为您的问题是您只有一个
完成的
变量。对于列表中的每个元素,都应该有一个
已完成的
变量。
将标记
CheckboxListTile
的布尔变量存储在
信息中,而不是存储在
信息中。completed
应存储在
信息中的每个元素。expandedValueData[index]。completed

我现在存储每个元素,并用info.expandedValueData[index]更改了信息。completed,在我得到错误“布尔表达式不能为空”后,我发布了上面编辑的代码,哪里有我的错误,没有完全成功地解决这个错误。不知道为什么,重新启动了新的应用程序,它工作了,代码应该是正确的,我想调试后有些问题已经解决了