From ea96773fd178b399be13d36c8918d7dec40c1fe0 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 2 May 2017 10:38:50 -0700 Subject: [PATCH] Use horizontal dots on iOS menu button (#9722) As required by . --- .../flutter/lib/src/material/popup_menu.dart | 14 ++++- .../test/material/popup_menu_test.dart | 51 ++++++++++++++++--- packages/flutter_test/lib/src/finders.dart | 25 +++++++++ 3 files changed, 81 insertions(+), 9 deletions(-) diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 6d2fab8e75..8e093b7881 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -543,11 +543,23 @@ class _PopupMenuButtonState extends State> { }); } + Icon _getIcon(TargetPlatform platform) { + assert(platform != null); + switch (platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + return const Icon(Icons.more_vert); + case TargetPlatform.iOS: + return const Icon(Icons.more_horiz); + } + return null; + } + @override Widget build(BuildContext context) { if (widget.child == null) { return new IconButton( - icon: const Icon(Icons.more_vert), + icon: _getIcon(Theme.of(context).platform), padding: widget.padding, tooltip: widget.tooltip, onPressed: showButtonMenu, diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index 630c63f870..e1bb007961 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -13,7 +13,7 @@ void main() { routes: { '/next': (BuildContext context) { return const Text('Next'); - } + }, }, home: new Material( child: new Center( @@ -29,15 +29,15 @@ void main() { const PopupMenuItem( value: 1, child: const Text('One') - ) + ), ]; - } + }, ); - } - ) - ) - ) - ) + }, + ), + ), + ), + ), ); await tester.tap(find.byKey(targetKey)); @@ -55,4 +55,39 @@ void main() { expect(find.text('One'), findsNothing); expect(find.text('Next'), findsOneWidget); }); + + testWidgets('PopupMenuButton is horizontal on iOS', (WidgetTester tester) async { + Widget build(TargetPlatform platform) { + return new MaterialApp( + theme: new ThemeData(platform: platform), + home: new Scaffold( + appBar: new AppBar( + actions: [ + new PopupMenuButton( + itemBuilder: (BuildContext context) { + return >[ + const PopupMenuItem( + value: 1, + child: const Text('One') + ), + ]; + }, + ), + ], + ), + ), + ); + } + + await tester.pumpWidget(build(TargetPlatform.android)); + + expect(find.byIcon(Icons.more_vert), findsOneWidget); + expect(find.byIcon(Icons.more_horiz), findsNothing); + + await tester.pumpWidget(build(TargetPlatform.iOS)); + await tester.pumpAndSettle(); // Run theme change animation. + + expect(find.byIcon(Icons.more_vert), findsNothing); + expect(find.byIcon(Icons.more_horiz), findsOneWidget); + }); } diff --git a/packages/flutter_test/lib/src/finders.dart b/packages/flutter_test/lib/src/finders.dart index cc9ef62f37..c9e0215d15 100644 --- a/packages/flutter_test/lib/src/finders.dart +++ b/packages/flutter_test/lib/src/finders.dart @@ -89,6 +89,16 @@ class CommonFinders { /// nodes that are [Offstage] or that are from inactive [Route]s. Finder byType(Type type, { bool skipOffstage: true }) => new _WidgetTypeFinder(type, skipOffstage: skipOffstage); + /// Finds widgets by searching for widgets with a particular icon data. + /// + /// Example: + /// + /// expect(find.byIcon(Icons.inbox), findsOneWidget); + /// + /// If the `skipOffstage` argument is true (the default), then this skips + /// nodes that are [Offstage] or that are from inactive [Route]s. + Finder byIcon(IconData icon, { bool skipOffstage: true }) => new _WidgetIconFinder(icon, skipOffstage: skipOffstage); + /// Finds widgets by searching for elements with a particular type. /// /// This does not do subclass tests, so for example @@ -428,6 +438,21 @@ class _WidgetTypeFinder extends MatchFinder { } } +class _WidgetIconFinder extends MatchFinder { + _WidgetIconFinder(this.icon, { bool skipOffstage: true }) : super(skipOffstage: skipOffstage); + + final IconData icon; + + @override + String get description => 'icon "$icon"'; + + @override + bool matches(Element candidate) { + final Widget widget = candidate.widget; + return widget is Icon && widget.icon == icon; + } +} + class _ElementTypeFinder extends MatchFinder { _ElementTypeFinder(this.elementType, { bool skipOffstage: true }) : super(skipOffstage: skipOffstage);