diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index c1dbc0988c..1a99e298cb 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -2169,7 +2169,10 @@ class _InputDecoratorState extends State with TickerProviderStat return border.copyWith( borderSide: BorderSide( color: _getDefaultM2BorderColor(themeData), - width: (decoration.isCollapsed || decoration.border == InputBorder.none || !decoration.enabled) + width: ( + (decoration.isCollapsed ?? themeData.inputDecorationTheme.isCollapsed) + || decoration.border == InputBorder.none + || !decoration.enabled) ? 0.0 : isFocused ? 2.0 : 1.0, ), @@ -2402,7 +2405,8 @@ class _InputDecoratorState extends State with TickerProviderStat final EdgeInsets contentPadding; final double floatingLabelHeight; - if (decoration.isCollapsed) { + if (decoration.isCollapsed + ?? themeData.inputDecorationTheme.isCollapsed) { floatingLabelHeight = 0.0; contentPadding = decorationContentPadding ?? EdgeInsets.zero; } else if (!border.isOutline) { @@ -2430,7 +2434,7 @@ class _InputDecoratorState extends State with TickerProviderStat final _Decorator decorator = _Decorator( decoration: _Decoration( contentPadding: contentPadding, - isCollapsed: decoration.isCollapsed, + isCollapsed: decoration.isCollapsed ?? themeData.inputDecorationTheme.isCollapsed, floatingLabelHeight: floatingLabelHeight, floatingLabelAlignment: decoration.floatingLabelAlignment!, floatingLabelProgress: _floatingLabelAnimation.value, @@ -2577,7 +2581,7 @@ class InputDecoration { this.errorMaxLines, this.floatingLabelBehavior, this.floatingLabelAlignment, - this.isCollapsed = false, + this.isCollapsed, this.isDense, this.contentPadding, this.prefixIcon, @@ -2976,7 +2980,7 @@ class InputDecoration { /// A collapsed decoration cannot have [labelText], [errorText], an [icon]. /// /// To create a collapsed input decoration, use [InputDecoration.collapsed]. - final bool isCollapsed; + final bool? isCollapsed; /// An icon that appears before the [prefix] or [prefixText] and before /// the editable part of the text field, within the decoration's container. @@ -3620,7 +3624,7 @@ class InputDecoration { floatingLabelAlignment: floatingLabelAlignment ?? theme.floatingLabelAlignment, isDense: isDense ?? theme.isDense, contentPadding: contentPadding ?? theme.contentPadding, - isCollapsed: isCollapsed, + isCollapsed: isCollapsed ?? theme.isCollapsed, iconColor: iconColor ?? theme.iconColor, prefixStyle: prefixStyle ?? theme.prefixStyle, prefixIconColor: prefixIconColor ?? theme.prefixIconColor, @@ -3782,7 +3786,7 @@ class InputDecoration { if (floatingLabelAlignment != null) 'floatingLabelAlignment: $floatingLabelAlignment', if (isDense ?? false) 'isDense: $isDense', if (contentPadding != null) 'contentPadding: $contentPadding', - if (isCollapsed) 'isCollapsed: $isCollapsed', + if (isCollapsed ?? false) 'isCollapsed: $isCollapsed', if (prefixIcon != null) 'prefixIcon: $prefixIcon', if (prefixIconColor != null) 'prefixIconColor: $prefixIconColor', if (prefix != null) 'prefix: $prefix', diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index 8647713698..b750c7a4f8 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -6570,4 +6570,25 @@ testWidgets('OutlineInputBorder with BorderRadius.zero should draw a rectangular expect(find.byType(InputDecorator), findsOneWidget); expect(tester.renderObject(find.text('COUNTER')).size, Size.zero); }); + + group('isCollapsed parameter works with themeData', () { + test('parameter is provided in InputDecorationTheme', () { + final InputDecoration decoration = const InputDecoration( + hintText: 'Hello, Flutter!', + ).applyDefaults(const InputDecorationTheme( + isCollapsed: true, + )); + + expect(decoration.isCollapsed, true); + }); + + test('parameter is provided in InputDecoration', () { + final InputDecoration decoration = const InputDecoration( + isCollapsed: true, + hintText: 'Hello, Flutter!', + ).applyDefaults(const InputDecorationTheme()); + + expect(decoration.isCollapsed, true); + }); + }); }