Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter: disable DropdownButtonFormField option

I have this widget:

DropdownButtonFormField<String>(
        hint: Text(translate('payments.select_frequency')),
        value: frequency,
        items: frequencies.map((String value) {
          return DropdownMenuItem<String>(
            value: value,
            child: Text(
              translate("expense.$value"),
              style: TextStyle(
                color: disabledFrequencies.contains(value) ? Colors.grey : null,
              ),
            ),
          );
        }).toList(),
        onChanged: (value) async {
          if (!disabledFrequencies.contains(value)) {
            setState(() {
              frequency = value;
            });
          }
        },
        validator: (value) {
          if (value == null) {
            return translate('fill_field');
          }
          return null;
        },
      );

This generates something like this:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

Here I should be able to just click the first option but I can select any of them. I opened this issue a while ago in Flutter repo and they mentioned it’s not an issue.

What’s the option then?

>Solution :

There is enable property on DropdownMenuItem control the tap accessibility.

return DropdownMenuItem<String>(
      value: value,
      enabled: !disabledFrequencies.contains(value), //this
      onTap: () {

Whether or not a user can select this menu item.
Defaults to true.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading