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:
@@ -110,7 +110,7 @@ class FlexibleSpaceDemoState extends State<FlexibleSpaceDemo> {
|
||||
_appBarBehavior = value;
|
||||
});
|
||||
},
|
||||
items: <PopupMenuItem<AppBarBehavior>>[
|
||||
itemBuilder: (BuildContext context) => <PopupMenuItem<AppBarBehavior>>[
|
||||
new PopupMenuItem<AppBarBehavior>(
|
||||
value: AppBarBehavior.scroll,
|
||||
child: new Text('AppBar scrolls away')
|
||||
|
||||
@@ -134,7 +134,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
|
||||
actions: <Widget>[
|
||||
new PopupMenuButton<LeaveBehindDemoAction>(
|
||||
onSelected: handleDemoAction,
|
||||
items: <PopupMenuEntry<LeaveBehindDemoAction>>[
|
||||
itemBuilder: (BuildContext context) => <PopupMenuEntry<LeaveBehindDemoAction>>[
|
||||
new PopupMenuItem<LeaveBehindDemoAction>(
|
||||
value: LeaveBehindDemoAction.reset,
|
||||
child: new Text('Reset the list')
|
||||
|
||||
@@ -64,7 +64,7 @@ class MenuDemoState extends State<MenuDemo> {
|
||||
actions: <Widget>[
|
||||
new PopupMenuButton<String>(
|
||||
onSelected: showMenuSelection,
|
||||
items: <PopupMenuItem<String>>[
|
||||
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
|
||||
new PopupMenuItem<String>(
|
||||
value: 'AppBar Menu',
|
||||
child: new Text('AppBar Menu')
|
||||
@@ -91,7 +91,7 @@ class MenuDemoState extends State<MenuDemo> {
|
||||
title: new Text('An item with a context menu button'),
|
||||
trailing: new PopupMenuButton<String>(
|
||||
onSelected: showMenuSelection,
|
||||
items: <PopupMenuItem<String>>[
|
||||
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
|
||||
new PopupMenuItem<String>(
|
||||
value: _simpleValue1,
|
||||
child: new Text('Context menu item one')
|
||||
@@ -114,7 +114,7 @@ class MenuDemoState extends State<MenuDemo> {
|
||||
title: new Text('An item with a sectioned menu'),
|
||||
trailing: new PopupMenuButton<String>(
|
||||
onSelected: showMenuSelection,
|
||||
items: <PopupMenuEntry<String>>[
|
||||
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
|
||||
new PopupMenuItem<String>(
|
||||
value: 'Preview',
|
||||
child: new ListItem(
|
||||
@@ -157,7 +157,7 @@ class MenuDemoState extends State<MenuDemo> {
|
||||
title: new Text('An item with a simple menu'),
|
||||
subtitle: new Text(_simpleValue)
|
||||
),
|
||||
items: <PopupMenuItem<String>>[
|
||||
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
|
||||
new PopupMenuItem<String>(
|
||||
value: _simpleValue1,
|
||||
child: new Text(_simpleValue1)
|
||||
@@ -178,7 +178,7 @@ class MenuDemoState extends State<MenuDemo> {
|
||||
title: new Text('An item with a checklist menu'),
|
||||
trailing: new PopupMenuButton<String>(
|
||||
onSelected: showCheckedMenuSelections,
|
||||
items: <PopupMenuItem<String>>[
|
||||
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
|
||||
new CheckedPopupMenuItem<String>(
|
||||
value: _checkedValue1,
|
||||
checked: isChecked(_checkedValue1),
|
||||
|
||||
@@ -53,7 +53,7 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> {
|
||||
actions: <Widget>[
|
||||
new PopupMenuButton<TabsDemoStyle>(
|
||||
onSelected: changeDemoStyle,
|
||||
items: <PopupMenuItem<TabsDemoStyle>>[
|
||||
itemBuilder: (BuildContext context) => <PopupMenuItem<TabsDemoStyle>>[
|
||||
new PopupMenuItem<TabsDemoStyle>(
|
||||
value: TabsDemoStyle.iconsAndText,
|
||||
child: new Text('Icons and Text')
|
||||
|
||||
@@ -220,7 +220,7 @@ class StockHomeState extends State<StockHome> {
|
||||
),
|
||||
new PopupMenuButton<_StockMenuItem>(
|
||||
onSelected: (_StockMenuItem value) { _handleStockMenu(context, value); },
|
||||
items: <PopupMenuItem<_StockMenuItem>>[
|
||||
itemBuilder: (BuildContext context) => <PopupMenuItem<_StockMenuItem>>[
|
||||
new CheckedPopupMenuItem<_StockMenuItem>(
|
||||
value: _StockMenuItem.autorefresh,
|
||||
checked: _autorefresh,
|
||||
|
||||
Reference in New Issue
Block a user