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> { ...@@ -712,13 +712,14 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
/// semantics. /// semantics.
Future<T> showMenu<T>({ Future<T> showMenu<T>({
@required BuildContext context, @required BuildContext context,
RelativeRect position, @required RelativeRect position,
@required List<PopupMenuEntry<T>> items, @required List<PopupMenuEntry<T>> items,
T initialValue, T initialValue,
double elevation = 8.0, double elevation = 8.0,
String semanticLabel, String semanticLabel,
}) { }) {
assert(context != null); assert(context != null);
assert(position != null);
assert(items != null && items.isNotEmpty); assert(items != null && items.isNotEmpty);
assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasMaterialLocalizations(context));
String label = semanticLabel; String label = semanticLabel;
......
...@@ -606,6 +606,41 @@ void main() { ...@@ -606,6 +606,41 @@ void main() {
expect(selectedValue, '2'); 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 { 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