mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
Made the showMenu() position parameter required (#30206)
Made the showMenu() position parameter required as it doesn't make sense to show a menu without indicating where it should be shown. Also added a test to verify this.
This commit is contained in:
parent
a3cbe25353
commit
3892a0d96c
|
@ -712,13 +712,14 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
|||
/// semantics.
|
||||
Future<T> showMenu<T>({
|
||||
@required BuildContext context,
|
||||
RelativeRect position,
|
||||
@required RelativeRect position,
|
||||
@required List<PopupMenuEntry<T>> items,
|
||||
T initialValue,
|
||||
double elevation = 8.0,
|
||||
String semanticLabel,
|
||||
}) {
|
||||
assert(context != null);
|
||||
assert(position != null);
|
||||
assert(items != null && items.isNotEmpty);
|
||||
assert(debugCheckHasMaterialLocalizations(context));
|
||||
String label = semanticLabel;
|
||||
|
|
|
@ -606,6 +606,41 @@ void main() {
|
|||
expect(selectedValue, '2');
|
||||
});
|
||||
|
||||
testWidgets('showMenu position required', (WidgetTester tester) async {
|
||||
// Test for https://github.com/flutter/flutter/issues/22256
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return RaisedButton(
|
||||
onPressed: () {
|
||||
// Ensure showMenu throws an assertion without a position
|
||||
expect(() {
|
||||
// ignore: missing_required_param
|
||||
showMenu<int>(
|
||||
context: context,
|
||||
items: <PopupMenuItem<int>>[
|
||||
const PopupMenuItem<int>(
|
||||
value: 1, child: Text('1')
|
||||
),
|
||||
],
|
||||
);
|
||||
}, throwsAssertionError);
|
||||
},
|
||||
child: const Text('Menu Button'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Menu Button'));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
class TestApp extends StatefulWidget {
|
||||
|
|
Loading…
Reference in a new issue