PopupMenuButtonis similar with the
DropdownButton, but has a bit different with it. The
PopupMenuButtonshows 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
initialValuewill highlight the item with a grey background when showing the menu. The
onCanceledis the function that will be called when you click the area that out of the menu.The
onSelectedis also a function with a value parameter that is the same as the value of the
iconshows our button for us to click. The result is below.
elevationcontrols the shadow of the menu. The
paddingsets the distance of the button.
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.