PopupMenuButton should lazily build menu items

Previously, the client of PopupMenuButton needed to build all the menu times

when building the PopupMenuButton. This can get expensive if, for example, each
item in a scrollable list has a popup menu associated with it.

Now the client passes a builder function to the PopupMenuButton that gets
invoked only when its time to show the menu items.
This commit is contained in:
Adam Barth
2016-04-06 13:28:09 -07:00
parent b930f0d4ff
commit 7ab122e557
7 changed files with 20 additions and 14 deletions

View File

@@ -101,7 +101,7 @@ class TopBarMenu extends StatelessWidget {
Widget build(BuildContext context) {
return new PopupMenuButton<String>(
onSelected: (String value) { print("Selected: $value"); },
items: <PopupMenuItem<String>>[
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
new PopupMenuItem<String>(
value: "Friends",
child: new MenuItemWithIcon(Icons.people, "Friends", "5 new")