From d868044e504d64b5461e08b89030b883b898e1dd Mon Sep 17 00:00:00 2001 From: Mehmet Fidanboylu Date: Thu, 7 Sep 2017 17:40:58 -0700 Subject: [PATCH] Selectively apply margin between middle and leading (#11964) * Selectively apply margin between middle and leading If ToolbarLayout does not have a leading widget, we should not put a margin between leading and middle areas since it ends up being blank space that looks odd. Fixes https://github.com/flutter/flutter/issues/11963 * Fix the failing test which is a good test case for missing leading widget --- packages/flutter/lib/src/widgets/navigation_toolbar.dart | 2 +- packages/flutter/test/material/app_bar_test.dart | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/flutter/lib/src/widgets/navigation_toolbar.dart b/packages/flutter/lib/src/widgets/navigation_toolbar.dart index f73f70ab95..2ccd5896ec 100644 --- a/packages/flutter/lib/src/widgets/navigation_toolbar.dart +++ b/packages/flutter/lib/src/widgets/navigation_toolbar.dart @@ -141,7 +141,7 @@ class _ToolbarLayout extends MultiChildLayoutDelegate { final BoxConstraints constraints = new BoxConstraints.loose(size).copyWith(maxWidth: maxWidth); final Size middleSize = layoutChild(_ToolbarSlot.middle, constraints); - final double middleStartMargin = leadingWidth + _kMiddleMargin; + final double middleStartMargin = hasChild(_ToolbarSlot.leading) ? leadingWidth + _kMiddleMargin : 0.0; double middleStart = middleStartMargin; final double middleY = (size.height - middleSize.height) / 2.0; // If the centered middle will not fit between the leading and trailing diff --git a/packages/flutter/test/material/app_bar_test.dart b/packages/flutter/test/material/app_bar_test.dart index c0b4df2577..0a3496fdec 100644 --- a/packages/flutter/test/material/app_bar_test.dart +++ b/packages/flutter/test/material/app_bar_test.dart @@ -157,7 +157,7 @@ void main() { expect(center.dx, lessThan(400 + size.width / 2.0)); }); - testWidgets('AppBar centerTitle:false title start edge is 16.0 (LTR)', (WidgetTester tester) async { + testWidgets('AppBar centerTitle:false title start edge is 0.0 (LTR)', (WidgetTester tester) async { await tester.pumpWidget( new MaterialApp( home: new Scaffold( @@ -169,10 +169,10 @@ void main() { ), ); - expect(tester.getTopLeft(find.text('X')).dx, 16.0); + expect(tester.getTopLeft(find.text('X')).dx, 0.0); }); - testWidgets('AppBar centerTitle:false title start edge is 16.0 (RTL)', (WidgetTester tester) async { + testWidgets('AppBar centerTitle:false title start edge is 0.0 (RTL)', (WidgetTester tester) async { await tester.pumpWidget( new MaterialApp( home: new Directionality( @@ -187,7 +187,7 @@ void main() { ), ); - expect(tester.getTopRight(find.text('X')).dx, 800.0 - 16.0); + expect(tester.getTopRight(find.text('X')).dx, 800.0); }); testWidgets(