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:
Darren Austin 2019-03-29 14:15:03 -07:00 committed by GitHub
parent a3cbe25353
commit 3892a0d96c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View file

@ -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;

View file

@ -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 {