From 3892a0d96c3e28ce9a1fe6269b95b2d92d598f2a Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Fri, 29 Mar 2019 14:15:03 -0700 Subject: [PATCH] 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. --- .../flutter/lib/src/material/popup_menu.dart | 3 +- .../test/material/popup_menu_test.dart | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index b1b47fc950..400e56cde8 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -712,13 +712,14 @@ class _PopupMenuRoute extends PopupRoute { /// semantics. Future showMenu({ @required BuildContext context, - RelativeRect position, + @required RelativeRect position, @required List> 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; diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index ed4a16ad20..f57ad57f64 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -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( + context: context, + items: >[ + const PopupMenuItem( + value: 1, child: Text('1') + ), + ], + ); + }, throwsAssertionError); + }, + child: const Text('Menu Button'), + ); + }, + ), + ), + ), + ) + ); + + await tester.tap(find.text('Menu Button')); + }); + } class TestApp extends StatefulWidget {