Placeholder Image

Subtitles section Play video

  • [MUSIC PLAYING]

  • KHANH NGUYEN: Need to provide users

  • with a way to select a value from a list of options?

  • Try DropdownButton.

  • To start, give it a list of options as DropdownMenuItems.

  • DropdownMenuItems represent the things you'll actually

  • see in the dropdown menu.

  • Since they're all in a list together,

  • they must all be of the same type.

  • Provide a state variable containing

  • the value of the selected DropdownMenuItem.

  • And finally, give it an onChanged callback that calls

  • setState() to update the variable when a new value is

  • selected.

  • Now, technically, you can stop right there,

  • or you can customize the DropdownButton

  • to your heart's content.

  • Is that arrow too small?

  • Make it bigger by adjusting the icon, Size.

  • Or perhaps the default gray doesn't stand out enough.

  • Give it a splash of color by providing an iconEnabledColor.

  • Don't even like the arrow?

  • Go ahead and replace it with a different icon.

  • Have the dropdown content horizontally fill its parent

  • by enabling isExpanded.

  • And you can even give the text a fresh coat of paint

  • by providing a style.

  • One thing to remember-- if either onChanged

  • or the list of items are null, the DropdownButton

  • gets disabled.

  • The arrow will be grayed out and it won't respond to input.

  • For more info on Flutter and all the other widgets,

  • head to Flutter.dev.

  • [MUSIC PLAYING]

[MUSIC PLAYING]

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it