Commit 57d6cc42 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Use platform-specific back icon in Scaffold (#6182)

parent b329894b
......@@ -614,8 +614,19 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
} else {
_shouldShowBackArrow ??= Navigator.canPop(context);
if (_shouldShowBackArrow) {
IconData backIcon;
switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
backIcon = Icons.arrow_back;
break;
case TargetPlatform.iOS:
backIcon = Icons.arrow_back_ios;
break;
}
assert(backIcon != null);
leading = new IconButton(
icon: new Icon(Icons.arrow_back),
icon: new Icon(backIcon),
alignment: FractionalOffset.centerLeft,
onPressed: () => Navigator.pop(context),
tooltip: 'Back' // TODO(ianh): Figure out how to localize this string
......
......@@ -238,4 +238,39 @@ void main() {
expect(appBarBottomRight, equals(sheetTopRight));
});
group('back arrow', () {
Future<Null> expectBackIcon(WidgetTester tester, TargetPlatform platform, IconData expectedIcon) async {
GlobalKey rootKey = new GlobalKey();
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/': (_) => new Container(key: rootKey, child: new Text('Home')),
'/scaffold': (_) => new Scaffold(
appBar: new AppBar(),
body: new Text('Scaffold'),
)
};
await tester.pumpWidget(
new MaterialApp(theme: new ThemeData(platform: platform), routes: routes)
);
Navigator.pushNamed(rootKey.currentContext, '/scaffold');
await tester.pump();
await tester.pump(const Duration(seconds: 1));
Icon icon = tester.widget(find.byType(Icon));
expect(icon.icon, expectedIcon);
}
testWidgets('Back arrow uses correct default on Android', (WidgetTester tester) async {
await expectBackIcon(tester, TargetPlatform.android, Icons.arrow_back);
});
testWidgets('Back arrow uses correct default on Fuchsia', (WidgetTester tester) async {
await expectBackIcon(tester, TargetPlatform.fuchsia, Icons.arrow_back);
});
testWidgets('Back arrow uses correct default on iOS', (WidgetTester tester) async {
await expectBackIcon(tester, TargetPlatform.iOS, Icons.arrow_back_ios);
});
});
}
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