0

My DropdownMenuItem coming from API. How to disable the dropDown once user select a item from the list?

child: DropdownButton<Partner>(
                          value:
                              _selectedLab, //USER SELECTED DROPDOWN ITEM VALUE
                          hint: Text("Select Lab"),
                          isExpanded: true,
                          items: data.map((Partner data) =>
                                  DropdownMenuItem<Partner>(
                                    child: Text("${data.partnerName}"),
                                    value: data,
                                  )).toList().cast<DropdownMenuItem<Partner>>(),
                          onChanged: (val) {
                            setState(() {
                              _selectedLab = val!;
                              encLabId = val.encPartnerId;
                              getTestByLabResult = getTestByLab();
                            });
                          },
                        ),
Toujo
  • 223
  • 1
  • 10

1 Answers1

1

Create a bool on state bool absoreTap = false; and wrap you DropdownButton with AbsorbPointer like

      AbsorbPointer(
              absorbing: absoreTap,
              child: DropdownButton<Partner>(
                          value:
                              _selectedLab, //USER SELECTED DROPDOWN ITEM VALUE
                          hint: Text("Select Lab"),
                          isExpanded: true,
                          items: data.map((Partner data) =>
                                  DropdownMenuItem<Partner>(
                                    child: Text("${data.partnerName}"),
                                    value: data,
                                  )).toList().cast<DropdownMenuItem<Partner>>(),
                          onChanged: (val) {
                            setState(() {
                              _selectedLab = val!;
                              encLabId = val.encPartnerId;
                              getTestByLabResult = getTestByLab();
                             absoreTap = true; /// 
                            });
                          },
                        ),

You can also check Ignore-pointer here is the different between them

Yeasin Sheikh
  • 16,243
  • 4
  • 15
  • 37