2

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

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

pretty simple. Just curious, is this a new thing?
I don't know when it came. Yes simple but very useful, I was trying to disable manually then found this on source code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.