Handle the case where InputDecorator is constrained to 0x0 (#17777)

This commit is contained in:
Hans Muller 2018-05-21 13:11:02 -07:00 committed by GitHub
parent eba194f776
commit 12bab13429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -764,14 +764,14 @@ class _RenderDecoration extends RenderBox {
if (suffixIcon != null) if (suffixIcon != null)
suffixIcon.layout(boxConstraints, parentUsesSize: true); suffixIcon.layout(boxConstraints, parentUsesSize: true);
final double inputWidth = constraints.maxWidth - ( final double inputWidth = math.max(0.0, constraints.maxWidth - (
_boxSize(icon).width _boxSize(icon).width
+ contentPadding.left + contentPadding.left
+ _boxSize(prefixIcon).width + _boxSize(prefixIcon).width
+ _boxSize(prefix).width + _boxSize(prefix).width
+ _boxSize(suffix).width + _boxSize(suffix).width
+ _boxSize(suffixIcon).width + _boxSize(suffixIcon).width
+ contentPadding.right); + contentPadding.right));
boxConstraints = boxConstraints.copyWith(maxWidth: inputWidth); boxConstraints = boxConstraints.copyWith(maxWidth: inputWidth);
if (label != null) // The label is not baseline aligned. if (label != null) // The label is not baseline aligned.
@ -811,10 +811,11 @@ class _RenderDecoration extends RenderBox {
// The helper or error text can occupy the full width less the space // The helper or error text can occupy the full width less the space
// occupied by the icon and counter. // occupied by the icon and counter.
boxConstraints = boxConstraints.copyWith( boxConstraints = boxConstraints.copyWith(
maxWidth: boxConstraints.maxWidth maxWidth: math.max(0.0, boxConstraints.maxWidth
- _boxSize(icon).width - _boxSize(icon).width
- _boxSize(counter).width - _boxSize(counter).width
- contentPadding.horizontal, - contentPadding.horizontal,
),
); );
layoutLineBox(helperError); layoutLineBox(helperError);

View File

@ -1408,4 +1408,24 @@ void main() {
], ],
)); ));
}); });
testWidgets('InputDecorator constrained to 0x0', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/17710
await tester.pumpWidget(
new Material(
child: new Directionality(
textDirection: TextDirection.ltr,
child: new UnconstrainedBox(child: new ConstrainedBox(
constraints: new BoxConstraints.tight(Size.zero),
child: const InputDecorator(
decoration: const InputDecoration(
labelText: 'XP',
border: const OutlineInputBorder(),
),
),
)),
),
),
);
});
} }