Unverified Commit dd1ee24f authored by Delwin Mathew's avatar Delwin Mathew Committed by GitHub

`InputDecorationTheme.isCollapsed` doesn't work if...

`InputDecorationTheme.isCollapsed` doesn't work if `InputDecoration.isCollapsed` is not provided. (#133189)

`appleDefault` method didn't include setting values for non-null (here `isCollapsed`) parameters initially, which has been updated and documented in this commit.

Existing and new tests are passing.

Fixes #133144
parent 9e9aa810
...@@ -2169,7 +2169,10 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat ...@@ -2169,7 +2169,10 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
return border.copyWith( return border.copyWith(
borderSide: BorderSide( borderSide: BorderSide(
color: _getDefaultM2BorderColor(themeData), 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 ? 0.0
: isFocused ? 2.0 : 1.0, : isFocused ? 2.0 : 1.0,
), ),
...@@ -2402,7 +2405,8 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat ...@@ -2402,7 +2405,8 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
final EdgeInsets contentPadding; final EdgeInsets contentPadding;
final double floatingLabelHeight; final double floatingLabelHeight;
if (decoration.isCollapsed) { if (decoration.isCollapsed
?? themeData.inputDecorationTheme.isCollapsed) {
floatingLabelHeight = 0.0; floatingLabelHeight = 0.0;
contentPadding = decorationContentPadding ?? EdgeInsets.zero; contentPadding = decorationContentPadding ?? EdgeInsets.zero;
} else if (!border.isOutline) { } else if (!border.isOutline) {
...@@ -2430,7 +2434,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat ...@@ -2430,7 +2434,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
final _Decorator decorator = _Decorator( final _Decorator decorator = _Decorator(
decoration: _Decoration( decoration: _Decoration(
contentPadding: contentPadding, contentPadding: contentPadding,
isCollapsed: decoration.isCollapsed, isCollapsed: decoration.isCollapsed ?? themeData.inputDecorationTheme.isCollapsed,
floatingLabelHeight: floatingLabelHeight, floatingLabelHeight: floatingLabelHeight,
floatingLabelAlignment: decoration.floatingLabelAlignment!, floatingLabelAlignment: decoration.floatingLabelAlignment!,
floatingLabelProgress: _floatingLabelAnimation.value, floatingLabelProgress: _floatingLabelAnimation.value,
...@@ -2577,7 +2581,7 @@ class InputDecoration { ...@@ -2577,7 +2581,7 @@ class InputDecoration {
this.errorMaxLines, this.errorMaxLines,
this.floatingLabelBehavior, this.floatingLabelBehavior,
this.floatingLabelAlignment, this.floatingLabelAlignment,
this.isCollapsed = false, this.isCollapsed,
this.isDense, this.isDense,
this.contentPadding, this.contentPadding,
this.prefixIcon, this.prefixIcon,
...@@ -2976,7 +2980,7 @@ class InputDecoration { ...@@ -2976,7 +2980,7 @@ class InputDecoration {
/// A collapsed decoration cannot have [labelText], [errorText], an [icon]. /// A collapsed decoration cannot have [labelText], [errorText], an [icon].
/// ///
/// To create a collapsed input decoration, use [InputDecoration.collapsed]. /// 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 /// An icon that appears before the [prefix] or [prefixText] and before
/// the editable part of the text field, within the decoration's container. /// the editable part of the text field, within the decoration's container.
...@@ -3620,7 +3624,7 @@ class InputDecoration { ...@@ -3620,7 +3624,7 @@ class InputDecoration {
floatingLabelAlignment: floatingLabelAlignment ?? theme.floatingLabelAlignment, floatingLabelAlignment: floatingLabelAlignment ?? theme.floatingLabelAlignment,
isDense: isDense ?? theme.isDense, isDense: isDense ?? theme.isDense,
contentPadding: contentPadding ?? theme.contentPadding, contentPadding: contentPadding ?? theme.contentPadding,
isCollapsed: isCollapsed, isCollapsed: isCollapsed ?? theme.isCollapsed,
iconColor: iconColor ?? theme.iconColor, iconColor: iconColor ?? theme.iconColor,
prefixStyle: prefixStyle ?? theme.prefixStyle, prefixStyle: prefixStyle ?? theme.prefixStyle,
prefixIconColor: prefixIconColor ?? theme.prefixIconColor, prefixIconColor: prefixIconColor ?? theme.prefixIconColor,
...@@ -3782,7 +3786,7 @@ class InputDecoration { ...@@ -3782,7 +3786,7 @@ class InputDecoration {
if (floatingLabelAlignment != null) 'floatingLabelAlignment: $floatingLabelAlignment', if (floatingLabelAlignment != null) 'floatingLabelAlignment: $floatingLabelAlignment',
if (isDense ?? false) 'isDense: $isDense', if (isDense ?? false) 'isDense: $isDense',
if (contentPadding != null) 'contentPadding: $contentPadding', if (contentPadding != null) 'contentPadding: $contentPadding',
if (isCollapsed) 'isCollapsed: $isCollapsed', if (isCollapsed ?? false) 'isCollapsed: $isCollapsed',
if (prefixIcon != null) 'prefixIcon: $prefixIcon', if (prefixIcon != null) 'prefixIcon: $prefixIcon',
if (prefixIconColor != null) 'prefixIconColor: $prefixIconColor', if (prefixIconColor != null) 'prefixIconColor: $prefixIconColor',
if (prefix != null) 'prefix: $prefix', if (prefix != null) 'prefix: $prefix',
......
...@@ -6570,4 +6570,25 @@ testWidgets('OutlineInputBorder with BorderRadius.zero should draw a rectangular ...@@ -6570,4 +6570,25 @@ testWidgets('OutlineInputBorder with BorderRadius.zero should draw a rectangular
expect(find.byType(InputDecorator), findsOneWidget); expect(find.byType(InputDecorator), findsOneWidget);
expect(tester.renderObject<RenderBox>(find.text('COUNTER')).size, Size.zero); expect(tester.renderObject<RenderBox>(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);
});
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment