You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中如何用Select2dot1下拉组件实现单组单选(仅选单分类项)

需求说明

仅希望从一个nameCategory中选择对应的nameSingleItem。例如存在10个nameCategory,每个分类下的nameSingleItem可能存在重复值,需确保仅选中单个分类下的选项。

代码示例
static const List<SingleCategoryModel> campOptions = [
    SingleCategoryModel(
      nameCategory: 'Camp Nomor 15',
      singleItemCategoryList: [
        SingleItemCategoryModel(nameSingleItem: "VVIP"),
        SingleItemCategoryModel(nameSingleItem: 'VIP'),
        SingleItemCategoryModel(nameSingleItem: 'Barrack'),
      ],
    ),
    SingleCategoryModel(
      nameCategory: 'Camp Nomor 16',
      singleItemCategoryList: [
        SingleItemCategoryModel(nameSingleItem: 'VIP'),
        SingleItemCategoryModel(nameSingleItem: 'Barrack'),
      ],
    ),
  ];

SizedBox(
  width: 300,
  child: Select2dot1(
    selectDataController: SelectDataController(
      data: campOptions,
      isMultiSelect: false, // false 表示选择单个选项,true 表示支持多选
    ),
    pillboxTitleSettings: const PillboxTitleSettings(
      title: '选择营地类型',
      titleStyleDefault: TextStyle(
        fontSize: 16,
        fontWeight: FontWeight.bold,
        color: Colors.black,
      ),
    ),
    pillboxSettings: PillboxSettings(
      defaultDecoration: BoxDecoration(
        border: Border.all(color: Colors.black, width: 1.5),
        borderRadius: BorderRadius.circular(8),
        color: Colors.white,
      ),
    ),
    onChanged: (selectedItems) {
      if (selectedItems.isNotEmpty) {
        final selectedItem = selectedItems.first;
        print("选中的营地类型: ${selectedItem.nameSingleItem}");
      }
    },
  ),
);

内容的提问来源于stack exchange,提问作者Cuma Dika ajah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 01:57:20