Commit ea96773f authored by Adam Barth's avatar Adam Barth Committed by GitHub
parent 6957eabe
......@@ -543,11 +543,23 @@ class _PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
});
}
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,
......
......@@ -13,7 +13,7 @@ void main() {
routes: <String, WidgetBuilder> {
'/next': (BuildContext context) {
return const Text('Next');
}
},
},
home: new Material(
child: new Center(
......@@ -29,15 +29,15 @@ void main() {
const PopupMenuItem<int>(
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: <Widget>[
new PopupMenuButton<int>(
itemBuilder: (BuildContext context) {
return <PopupMenuItem<int>>[
const PopupMenuItem<int>(
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);
});
}
......@@ -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);
......
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