diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 32b2cc5218..ab8660e6bf 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -2622,19 +2622,26 @@ class InputDecoration { /// /// This type of input decoration does not include a border by default. /// + /// A collapsed decoration cannot have [labelText], [errorText], [counter], + /// [icon], prefixes, and suffixes. + /// /// Sets the [isCollapsed] property to true. + /// Sets the [contentPadding] property to [EdgeInsets.zero]. const InputDecoration.collapsed({ required this.hintText, this.floatingLabelBehavior, this.floatingLabelAlignment, this.hintStyle, this.hintTextDirection, + this.hintMaxLines, + this.hintFadeDuration, this.filled = false, this.fillColor, this.focusColor, this.hoverColor, this.border = InputBorder.none, this.enabled = true, + this.constraints, }) : icon = null, iconColor = null, label = null, @@ -2645,8 +2652,6 @@ class InputDecoration { helperText = null, helperStyle = null, helperMaxLines = null, - hintMaxLines = null, - hintFadeDuration = null, error = null, errorText = null, errorStyle = null, @@ -2675,8 +2680,7 @@ class InputDecoration { disabledBorder = null, enabledBorder = null, semanticCounterText = null, - alignLabelWithHint = false, - constraints = null; + alignLabelWithHint = false; /// An icon to show before the input field and outside of the decoration's /// container. @@ -3019,7 +3023,8 @@ class InputDecoration { /// Whether the decoration is the same size as the input field. /// - /// A collapsed decoration cannot have [labelText], [errorText], an [icon]. + /// A collapsed decoration cannot have [labelText], [errorText], [counter], + /// [icon], prefixes, and suffixes. /// /// To create a collapsed input decoration, use [InputDecoration.collapsed]. final bool? isCollapsed; @@ -3881,7 +3886,7 @@ class InputDecoration { /// the current input decoration theme to initialize null [InputDecoration] /// properties. /// -/// The [InputDecoration.applyDefaults] method is used to combine a input +/// The [InputDecoration.applyDefaults] method is used to combine an input /// decoration theme with an [InputDecoration] object. @immutable class InputDecorationTheme with Diagnosticable { diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index 74bbf0ba27..6dfdd10ad6 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -6523,6 +6523,70 @@ void main() { expect(getBorderWeight(tester), 0.0); }); + testWidgets('InputDecoration.collapsed accepts constraints', (WidgetTester tester) async { + await tester.pumpWidget( + buildInputDecorator( + decoration: const InputDecoration.collapsed( + hintText: hintText, + constraints: BoxConstraints.tightFor(width: 200.0, height: 32.0), + ), + ), + ); + + expect(getDecoratorRect(tester).size, const Size(200.0, 32.0)); + }); + + testWidgets('InputDecoration.collapsed accepts hintMaxLines', (WidgetTester tester) async { + await tester.pumpWidget( + buildInputDecorator( + decoration: const InputDecoration.collapsed( + hintText: threeLines, + hintMaxLines: 2, + ), + ), + ); + + const double hintLineHeight = 24.0; // font size = 16 and font height = 1.5. + expect(getDecoratorRect(tester).size, const Size(800.0, 2 * hintLineHeight)); + }); + + testWidgets('InputDecoration.collapsed accepts hintFadeDuration', (WidgetTester tester) async { + // Build once with empty content. + await tester.pumpWidget( + buildInputDecorator( + isEmpty: true, + decoration: const InputDecoration.collapsed( + hintText: hintText, + hintFadeDuration: Duration(milliseconds: 120), + ), + ), + ); + + // Hint is visible (opacity 1.0). + expect(getHintOpacity(tester), 1.0); + + // Rebuild with non-empty content. + await tester.pumpWidget( + buildInputDecorator( + decoration: const InputDecoration.collapsed( + hintText: hintText, + hintFadeDuration: Duration(milliseconds: 120), + ), + ), + ); + + // The hint's opacity animates from 1.0 to 0.0. + // The animation's default duration is 20ms. + await tester.pump(const Duration(milliseconds: 50)); + final double hintOpacity50ms = getHintOpacity(tester); + expect(hintOpacity50ms, inExclusiveRange(0.0, 1.0)); + await tester.pump(const Duration(milliseconds: 50)); + final double hintOpacity100ms = getHintOpacity(tester); + expect(hintOpacity100ms, inExclusiveRange(0.0, hintOpacity50ms)); + await tester.pump(const Duration(milliseconds: 50)); + expect(getHintOpacity(tester), 0.0); + }); + test('InputDecorationTheme.isCollapsed is applied', () { final InputDecoration decoration = const InputDecoration( hintText: 'Hello, Flutter!',