From c43134a71c2f84c864a2a574ee8661fd110ce7a3 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Tue, 10 Apr 2018 12:02:52 -0700 Subject: [PATCH] Fixes a problem with the height of the chip label (#16420) There was a bug in the size calculation for the height of the chip label, where it would force the label to be larger than it wanted to be, causing text to not be vertically centered. --- packages/flutter/lib/src/material/chip.dart | 28 +++++++++++++------ packages/flutter/test/material/chip_test.dart | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index 5398f340d7..f933a76ffa 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -1892,22 +1892,33 @@ class _RenderChip extends RenderBox { } Size _layoutLabel(double iconSizes, Size size) { + final Size rawSize = _boxSize(label); // Now that we know the label height and the width of the icons, we can // determine how much to shrink the width constraints for the "real" layout. if (constraints.maxWidth.isFinite) { label.layout( - constraints.loosen().copyWith( - maxWidth: math.max( - 0.0, - constraints.maxWidth - iconSizes - theme.labelPadding.horizontal, - ), - maxHeight: size.height), + constraints.copyWith( + minWidth: 0.0, + maxWidth: math.max( + 0.0, + constraints.maxWidth - iconSizes - theme.labelPadding.horizontal, + ), + minHeight: rawSize.height, + maxHeight: size.height, + ), parentUsesSize: true, ); } else { - label.layout(new BoxConstraints.tight(size), parentUsesSize: true); + label.layout( + new BoxConstraints( + minHeight: rawSize.height, + maxHeight: size.height, + minWidth: 0.0, + maxWidth: size.width, + ), + parentUsesSize: true, + ); } - final Size rawSize = _boxSize(label); return new Size( rawSize.width + theme.labelPadding.horizontal, rawSize.height + theme.labelPadding.vertical, @@ -2064,7 +2075,6 @@ class _RenderChip extends RenderBox { } else { deleteButtonRect = Rect.zero; } - //assert(start + deleteIconSize.width == overallSize.width); break; } // Center the label vertically. diff --git a/packages/flutter/test/material/chip_test.dart b/packages/flutter/test/material/chip_test.dart index 5eb6be4103..bfd064b278 100644 --- a/packages/flutter/test/material/chip_test.dart +++ b/packages/flutter/test/material/chip_test.dart @@ -200,7 +200,7 @@ void main() { ), ), ); - expect(tester.getSize(find.byType(Text)), const Size(40.0, 24.0)); + expect(tester.getSize(find.byType(Text)), const Size(40.0, 10.0)); expect(tester.getSize(find.byType(Chip)), const Size(64.0, 32.0)); await tester.pumpWidget( new MaterialApp(