Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
08c83591
Unverified
Commit
08c83591
authored
Feb 14, 2020
by
creativecreatorormaybenot
Committed by
GitHub
Feb 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose showButtonMenu of PopupMenuButtonState (#50670)
parent
63ca3348
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
2 deletions
+49
-2
popup_menu.dart
packages/flutter/lib/src/material/popup_menu.dart
+14
-2
popup_menu_test.dart
packages/flutter/test/material/popup_menu_test.dart
+35
-0
No files found.
packages/flutter/lib/src/material/popup_menu.dart
View file @
08c83591
...
...
@@ -1037,10 +1037,22 @@ class PopupMenuButton<T> extends StatefulWidget {
final
bool
captureInheritedThemes
;
@override
_PopupMenuButtonState
<
T
>
createState
()
=>
_
PopupMenuButtonState
<
T
>();
PopupMenuButtonState
<
T
>
createState
()
=>
PopupMenuButtonState
<
T
>();
}
class
_PopupMenuButtonState
<
T
>
extends
State
<
PopupMenuButton
<
T
>>
{
/// The [State] for a [PopupMenuButton].
///
/// See [showButtonMenu] for a way to programmatically open the popup menu
/// of your button state.
class
PopupMenuButtonState
<
T
>
extends
State
<
PopupMenuButton
<
T
>>
{
/// A method to show a popup menu with the items supplied to
/// [PopupMenuButton.itemBuilder] at the position of your [PopupMenuButton].
///
/// By default, it is called when the user taps the button and [PopupMenuButton.enabled]
/// is set to `true`. Moreover, you can open the button by calling the method manually.
///
/// You would access your [PopupMenuButtonState] using a [GlobalKey] and
/// show the menu of the button with `globalKey.currentState.showButtonMenu`.
void
showButtonMenu
()
{
final
PopupMenuThemeData
popupMenuTheme
=
PopupMenuTheme
.
of
(
context
);
final
RenderBox
button
=
context
.
findRenderObject
()
as
RenderBox
;
...
...
packages/flutter/test/material/popup_menu_test.dart
View file @
08c83591
...
...
@@ -1197,6 +1197,41 @@ void main() {
expect
(
rootObserver
.
menuCount
,
1
);
expect
(
nestedObserver
.
menuCount
,
0
);
});
testWidgets
(
'PopupMenuButton calling showButtonMenu manually'
,
(
WidgetTester
tester
)
async
{
final
GlobalKey
<
PopupMenuButtonState
<
int
>>
globalKey
=
GlobalKey
();
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
Column
(
children:
<
Widget
>[
PopupMenuButton
<
int
>(
key:
globalKey
,
itemBuilder:
(
BuildContext
context
)
{
return
<
PopupMenuEntry
<
int
>>[
const
PopupMenuItem
<
int
>(
value:
1
,
child:
Text
(
'Tap me please!'
),
),
];
},
),
],
),
),
)
);
expect
(
find
.
text
(
'Tap me please!'
),
findsNothing
);
globalKey
.
currentState
.
showButtonMenu
();
// The PopupMenuItem will appear after an animation, hence,
// we have to first wait for the tester to settle.
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Tap me please!'
),
findsOneWidget
);
});
}
class
TestApp
extends
StatefulWidget
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment