From 12bab134293c94718d420edb55c11b225b834301 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Mon, 21 May 2018 13:11:02 -0700 Subject: [PATCH] Handle the case where InputDecorator is constrained to 0x0 (#17777) --- .../lib/src/material/input_decorator.dart | 7 ++++--- .../test/material/input_decorator_test.dart | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 39fa2d71ad..672011a700 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -764,14 +764,14 @@ class _RenderDecoration extends RenderBox { if (suffixIcon != null) suffixIcon.layout(boxConstraints, parentUsesSize: true); - final double inputWidth = constraints.maxWidth - ( + final double inputWidth = math.max(0.0, constraints.maxWidth - ( _boxSize(icon).width + contentPadding.left + _boxSize(prefixIcon).width + _boxSize(prefix).width + _boxSize(suffix).width + _boxSize(suffixIcon).width - + contentPadding.right); + + contentPadding.right)); boxConstraints = boxConstraints.copyWith(maxWidth: inputWidth); 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 // occupied by the icon and counter. boxConstraints = boxConstraints.copyWith( - maxWidth: boxConstraints.maxWidth + maxWidth: math.max(0.0, boxConstraints.maxWidth - _boxSize(icon).width - _boxSize(counter).width - contentPadding.horizontal, + ), ); layoutLineBox(helperError); diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index ae00bf20fc..94b8cf6d50 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -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(), + ), + ), + )), + ), + ), + ); + }); }