【问题标题】:Multiple select options in flutter颤振中的多个选择选项
【发布时间】:2021-10-09 07:44:09
【问题描述】:

我想创建一个选项芯片列表并在其中选择多个选项。我还想在选择选项时更改颜色。选项是动态的。 我尝试使用以下功能,但 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;
  }

【问题讨论】:

    标签: flutter multi-select chips


    【解决方案1】:

    使用这个插件here 这是一个项目的示例代码

     Expanded(
        child: MultiSelectDialogField(
        initialValue:
        profileImage['height'] ?? [],
        searchable: true,
        listType: MultiSelectListType.CHIP,
        buttonText: heightList.isEmpty
        ? Text(
        "No Hieght",
        style: TextStyle(
        color: Colors.white,
        fontSize: 20,
         ),
        )
        : Text(
        "Height",
        style: TextStyle(
        color: Colors.white,
       fontSize: 20,
       ),
       ),
      title: Text('Height'),
      items: HeightList().height.map((e) => MultiSelectItem(e, e))
      .toList(),
       decoration: BoxDecoration(color:Colors.white.withOpacity(0.2),
        borderRadius:BorderRadius.circular(10),),
        buttonIcon: Icon(Icons.arrow_drop_down_outlined,
        color:Colors.white.withOpacity(0.7),),
        onConfirm: (values) {
        heightList = values;
        setState(() {
       heightLenght = heightList.length;
       });
       },
        chipDisplay: MultiSelectChipDisplay( onTap: (value) {
        setState(() {
                                                        heightList.remove(value);
        });
        },
        ),
        )),
    

    【讨论】:

      猜你喜欢
      • 2021-06-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2021-06-29
      • 2021-07-29
      • 1970-01-01
      • 2022-11-21
      相关资源
      最近更新 更多