Skip to content

Commit d868044

Browse files
authored
Selectively apply margin between middle and leading (flutter#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 flutter#11963 * Fix the failing test which is a good test case for missing leading widget
1 parent 60c4ff9 commit d868044

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/flutter/lib/src/widgets/navigation_toolbar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class _ToolbarLayout extends MultiChildLayoutDelegate {
141141
final BoxConstraints constraints = new BoxConstraints.loose(size).copyWith(maxWidth: maxWidth);
142142
final Size middleSize = layoutChild(_ToolbarSlot.middle, constraints);
143143

144-
final double middleStartMargin = leadingWidth + _kMiddleMargin;
144+
final double middleStartMargin = hasChild(_ToolbarSlot.leading) ? leadingWidth + _kMiddleMargin : 0.0;
145145
double middleStart = middleStartMargin;
146146
final double middleY = (size.height - middleSize.height) / 2.0;
147147
// If the centered middle will not fit between the leading and trailing

packages/flutter/test/material/app_bar_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void main() {
157157
expect(center.dx, lessThan(400 + size.width / 2.0));
158158
});
159159

160-
testWidgets('AppBar centerTitle:false title start edge is 16.0 (LTR)', (WidgetTester tester) async {
160+
testWidgets('AppBar centerTitle:false title start edge is 0.0 (LTR)', (WidgetTester tester) async {
161161
await tester.pumpWidget(
162162
new MaterialApp(
163163
home: new Scaffold(
@@ -169,10 +169,10 @@ void main() {
169169
),
170170
);
171171

172-
expect(tester.getTopLeft(find.text('X')).dx, 16.0);
172+
expect(tester.getTopLeft(find.text('X')).dx, 0.0);
173173
});
174174

175-
testWidgets('AppBar centerTitle:false title start edge is 16.0 (RTL)', (WidgetTester tester) async {
175+
testWidgets('AppBar centerTitle:false title start edge is 0.0 (RTL)', (WidgetTester tester) async {
176176
await tester.pumpWidget(
177177
new MaterialApp(
178178
home: new Directionality(
@@ -187,7 +187,7 @@ void main() {
187187
),
188188
);
189189

190-
expect(tester.getTopRight(find.text('X')).dx, 800.0 - 16.0);
190+
expect(tester.getTopRight(find.text('X')).dx, 800.0);
191191
});
192192

193193
testWidgets(

0 commit comments

Comments
 (0)