0

My code is :

 Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: 'Select District',
                                style: getSemiBoldStyle(
                                    color: Colormanager.lightGrey,
                                    fontSize: AppSize.s14),
                              ),
                              TextSpan(
                                text: AppStrings.star,
                                style: getSemiBoldStyle(
                                    color: Colormanager.red,
                                    fontSize: AppSize.s14),
                              ),
                            ],
                          ),
                        ),
                        const SizedBox(
                          height: AppSize.s4,
                        ),
                        DropdownSearch<CoverageArea>(
                          popupProps: PopupProps.menu(
                            showSearchBox: true,
                            // disabledItemFn: (String s) => s.startsWith('I'),
                            searchFieldProps: TextFieldProps(
                              style: getBoldStyle(
                                  color: Colormanager.black,
                                  fontSize: FontSize.s15),
                            ),
                            itemBuilder: (context, item, isSelected) =>
                            isSelected
                                ? Padding(
                              padding: const EdgeInsets.all(8.0),
                              child: Text(
                                item.district!,
                                style: getBoldStyle(
                                    color: Colormanager.primary),
                              ),
                            )
                                : Container(
                              padding: const EdgeInsets.all(8.0),
                              margin: const EdgeInsets.only(
                                  bottom: 4),
                              color: Colormanager.lightGrey
                                  .withOpacity(0.2),
                              child: Text(
                                item.district!,
                                style: getBoldStyle(
                                    color: Colormanager.black,
                                    fontSize: FontSize.s15),
                              ),
                            ),
                          ),
                          items: controller.coverageAreas,

                          dropdownDecoratorProps: DropDownDecoratorProps(
                            baseStyle:
                            getSemiBoldStyle(color: Colormanager.black),
                            dropdownSearchDecoration: const InputDecoration(
                              // labelText: "Menu mode",
                              // hintText: "country in menu mode",

                            ),
                          ),
                          onChanged: (value) {
                            controller.selectedDistrict = value;
                            controller.selectDistrict.value =
                                value!.district.toString();
                          },
                          itemAsString: (item) => item.district.toString(),

                          // selectedItem: controller.selectArea.value,
                        ),
                      ],
                    ),

and the api call show me :

 {
    "Status": true,
    "message": "Coverage Area List",
    "data": [
        {
            "id": 898,
            "inside": 0,
            "zone_name": "OSD Operation",
            "district": "Barguna",
            "area": "Barguna Sadar",
            "district_id": 35,
            "zone_id": 14,
            "post_code": null,
            "h_delivery": null,
            "oneRe": null,
            "oneUr": null,
            "plusRe": null,
            "plusUr": null,
            "cod": null,
            "insurance": null,
            "status": 0,
            "created_at": "2023-01-17 15:40:08",
            "updated_at": "2023-01-17 15:40:08"
        },
        {
            "id": 897,
            "inside": 0,
            "zone_name": "OSD Operation",
            "district": "Barguna",
            "area": "Taltoly",
            "district_id": 35,
            "zone_id": 14,
            "post_code": null,
            "h_delivery": null,
            "oneRe": null,
            "oneUr": null,
            "plusRe": null,
            "plusUr": null,
            "cod": null,
            "insurance": null,
            "status": 0,
            "created_at": "2023-01-17 15:39:49",
            "updated_at": "2023-01-17 15:39:49"
        },
        {
            "id": 896,
            "inside": 0,
            "zone_name": "OSD Operation",
            "district": "Barguna",
            "area": "Amtoly",
            "district_id": 35,
            "zone_id": 14,
            "post_code": null,
            "h_delivery": null,
            "oneRe": null,
            "oneUr": null,
            "plusRe": null,
            "plusUr": null,
            "cod": null,
            "insurance": null,
            "status": 0,
            "created_at": "2023-01-17 15:39:29",
            "updated_at": "2023-01-17 15:39:29"
        },
        {
            "id": 895,
            "inside": 0,
            "zone_name": "OSD Operation",
            "district": "Barguna",
            "area": "Betage",
            "district_id": 35,
            "zone_id": 14,
            "post_code": null,
            "h_delivery": null,
            "oneRe": null,
            "oneUr": null,
            "plusRe": null,
            "plusUr": null,
            "cod": null,
            "insurance": null,
            "status": 0,
            "created_at": "2023-01-17 15:39:05",
            "updated_at": "2023-01-17 15:39:05"
        },
    {
            "id": 891,
            "inside": 0,
            "zone_name": "OSD Operation",
            "district": "Barishal",
            "area": "Barisal Bandor Thana",
            "district_id": 33,
            "zone_id": 14,
            "post_code": null,
            "h_delivery": null,
            "oneRe": null,
            "oneUr": null,
            "plusRe": null,
            "plusUr": null,
            "cod": null,
            "insurance": null,
            "status": 0,
            "created_at": "2023-01-17 15:35:28",
            "updated_at": "2023-01-17 15:35:28"
        },

so on..............

I want to show Barguna district just once and area in dependable dropdownbutton in next. but how can i do it???

This is the output how can i just show one name just once???

Bas H
  • 2,114
  • 10
  • 14
  • 23

1 Answers1

0

While there are multiple items contains single value, I will suggest you to use String dataType instead of CoverageArea. then you can create a set of string from data.

So the item will be like

final List<String> items = controller.coverageAreas.map((e)=> e.district.trim()).toSet().toList();

now use this items on dropdown. and the value will be return as String DropdownSearch<String>(

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56