【问题标题】:Flutter -Checkbox inside ListviewFlutter -Listview内的复选框
【发布时间】:2020-04-01 01:22:51
【问题描述】:

ListView 中的复选框有问题。 每次我在列表中添加新项目时,检查都会向下移动。如果我删除一个项目,检查会向上移动。我需要一些帮助,伙计们。谢谢! 请查看下面的演示。

Demo

【问题讨论】:

    标签: list listview flutter checkbox


    【解决方案1】:
    CheckboxListTile(
          title: const Text('Is Active'),
          value: checkedOrNot,
          onChanged: (bool newValue) {
            setState(() { 
                checkedOrNot = newValue
            });
          },
          secondary: const Icon(Icons.hourglass_empty),
        ),
    

    Row(
      children: <Widget>[
        Expanded(
          child: Text('Is Active', textAlign: TextAlign.center),
        ),
        Expanded(
          child: Checkbox(
                 value: checkedOrNot, //bool
                 onChanged: (bool newValue) {
                         setState(() {
                        checkedOrNot = newValue;
                     });
                    },
              )
        ),
      ],
    )
    

    【讨论】:

    • 我的代码和你的一样。正如您在演示中看到的那样,有一个 3 复选框,并且中间的复选框被选中。所以当我在列表中添加一个新项目时,检查被向下移动。即使中间是我选中的复选框,检查也会出现在最后一个复选框中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    相关资源
    最近更新 更多