0

I'm trying to use Montserrat with a custom color on my DropdownButton but for some reason, the TextStyle is not being applied.

Here is my code:

DropdownButton(
  value: value,
  dropdownColor: colorScheme.surface,
  hint: hint != null
      ? Text(
          hint,
          style: GoogleFonts.montserrat(
            fontSize: 18,
            color: colorScheme.onPrimary,
          ),
        )
      : null,
  style: GoogleFonts.montserrat(
    fontSize: 18,
    color: colorScheme.onPrimary,
  ),
  iconEnabledColor: colorScheme.onPrimary,
  items: items
      .map((e) => DropdownMenuItem(
            alignment: Alignment.center,
            value: e,
            child: Text(
              e,
              style: GoogleFonts.montserrat(
                fontSize: 18,
                color: colorScheme.onSurface,
              ),
            ),
          ))
      .toList(),
  onChanged: onChanged,
);

I can't find where or how it's wrong.

1
  • I tried your code and it worked (all styles applied). Maybe you need to hot restart? Commented Oct 14, 2023 at 14:27

2 Answers 2

1

Reading the documentation found what actually works:

selectedItemBuilder: (BuildContext context) {
          return items.map((String value) {
            return Align(
              alignment: Alignment.center,
              child: Text(
                value,
                style: GoogleFonts.montserrat(
                    fontSize: 18, color: colorScheme.onPrimary),
              ),
            );
          }).toList();
        },

This atribute did the trick.

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

Comments

0

Style's property on dropdown are quite tricky as you have several style possible (dropdown itself, dropdown items, hint...). Basically on your question's code sample, you only apply style to items in the dropdown, the field's hint and eventually some decoration based on main "style" property.

seletectedItemBuilder is indeed the thing you're looking for as it will stylish (or customize the display) of the item shown when users have selected a value in the list :)

Comments

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.