Unverified Commit 3892a0d9 authored by Darren Austin's avatar Darren Austin Committed by GitHub

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.
parent a3cbe253
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment