标签: chips

flutter 中的多个选择选项

我想创建一个选项芯片列表,并在其中选择多个选项。我还想在选择选项时更改颜色。选项是动态的。我尝试使用以下函数,但 onselectionchanged 显示空错误,并且点击时颜色不会改变。请问有什么建议吗??

_buildChoiceList() {
    List<Widget> choices = [];
    options.forEach((item) {
      choices.add(Container(
        padding: const EdgeInsets.all(2.0),
        child: ChoiceChip(
          label: Text(item),
          selected: selectedOptions.contains(item),
          backgroundColor: Color(0xffff08222),
          onSelected: (selected) {
            setState(() {
              selectedOptions.contains(item)
                  ? selectedOptions.remove(item)
                  : selectedOptions.add(item);
              widget.onSelectionChanged(selectedOptions);
            });
          },
        ),
      ));
    });
    return choices;
  }
Run Code Online (Sandbox Code Playgroud)

multi-select flutter chips

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

chips ×1

flutter ×1

multi-select ×1