PopupMenuButton
is similar with the DropdownButton
, but has a bit different with it. The PopupMenuButton
shows the menu but do not change the current button,you can do more things than the DropdownButton
. So let's look at an example.PopupMenuEntry
. It is an abstract class, so we should use its subclasses. The relationship of the extends is below.PopupMenuItem
, the middle line the PopupMenuDivider
, the bottom one is the CheckedPopupMenuItem
. initialValue
will highlight the item with a grey background when showing the menu. The onCanceled
is the function that will be called when you click the area that out of the menu.The onSelected
is also a function with a value parameter that is the same as the value of the PopupMenuItem
. The icon
shows our button for us to click. The result is below.elevation
controls the shadow of the menu. The padding
sets the distance of the button.child
or icon
, do not use both of them.Offset(0,100)
, which position it will be.Offset.zero
.It will show as below.PopupMenuButton
. A bit difficult one is the itemBuilder
, it isn't very obvious to a newer, it is a function that return list. The others will be easy to understand.