Both of the widgets look almost similar. So, what is the exact use case of them? Also, how do you set the width of the DropdownMenu, not the entries?
Both of the widgets look almost similar. So, what is the exact use case of them? Also, how do you set the width of the DropdownMenu, not the entries?
2
Answers
DropdownMenu
is a stateless widget that represents the drop-down menu itself. It does not have any state of its own, and it depends on the DropdownButton widget to provide the list of items and the currently selected item.DropdownButton
is a stateful widget that represents the drop-down button itself. It has state for the list of items, the currently selected item, and the on-change callback.In other words,
DropdownMenu
is a "dumb" widget that just displays the drop-down menu, whileDropdownButton
is a "smart" widget that handles the logic of displaying the list of items, selecting an item, and calling the on-change callback.1. DropdownButton:
*DropdownButton is a Flutter widget that provides a clickable button with a dropdown arrow, and when clicked, it displays a list of items in a popup menu. It’s used when you want to provide a single selectable option from a list of items. When an item is selected from the dropdown menu, the button’s label changes to the selected item’s label.
2.DropdownMenu:
There isn’t a widget called DropdownMenu in the official Flutter library as of my knowledge cutoff date is September 2021. However, you might be referring to the PopupMenuButton widget. This widget creates a button that, when pressed, displays a popup menu with a list of items.
PopupMenuButton is used when you want to show a list of menu items in response to a user action (like a right-click or a long press), rather than as a direct replacement for a selection widget like DropdownButton.