Use platform-specific back icon in Scaffold (#6182)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user