From 1d726bbeb530cfbf6585f560a35b7e42c6f8c106 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 2 May 2017 12:53:03 -0700 Subject: [PATCH] Left align AppBar title on iOS with multiple actions (#9723) If there is more than one action, then the AppBar should align the title to the left according to --- .../flutter/lib/src/material/app_bar.dart | 2 +- .../flutter/test/material/app_bar_test.dart | 43 ++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 73274c8a99..5f37d00467 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -311,7 +311,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget { case TargetPlatform.fuchsia: return false; case TargetPlatform.iOS: - return true; + return actions == null || actions.length < 2; } return null; } diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart index e95cd037a6..a0d34e710e 100644 --- a/packages/flutter/test/material/app_bar_test.dart +++ b/packages/flutter/test/material/app_bar_test.dart @@ -90,6 +90,48 @@ void main() { size = tester.getSize(title); expect(center.dx, greaterThan(400 - size.width / 2.0)); expect(center.dx, lessThan(400 + size.width / 2.0)); + + // One action is still centered. + + await tester.pumpWidget( + new MaterialApp( + theme: new ThemeData(platform: TargetPlatform.iOS), + home: new Scaffold( + appBar: new AppBar( + title: const Text('X'), + actions: [ + const Icon(Icons.thumb_up), + ], + ), + ), + ), + ); + + center = tester.getCenter(title); + size = tester.getSize(title); + expect(center.dx, greaterThan(400 - size.width / 2.0)); + expect(center.dx, lessThan(400 + size.width / 2.0)); + + // Two actions is left aligned again. + + await tester.pumpWidget( + new MaterialApp( + theme: new ThemeData(platform: TargetPlatform.iOS), + home: new Scaffold( + appBar: new AppBar( + title: const Text('X'), + actions: [ + const Icon(Icons.thumb_up), + const Icon(Icons.thumb_up), + ], + ), + ), + ), + ); + + center = tester.getCenter(title); + size = tester.getSize(title); + expect(center.dx, lessThan(400 - size.width / 2.0)); }); testWidgets('AppBar centerTitle:true centers on Android', (WidgetTester tester) async { @@ -105,7 +147,6 @@ void main() { ) ); - final Finder title = find.text('X'); final Offset center = tester.getCenter(title); final Size size = tester.getSize(title);