Skip to content

Commit dd1ee24

Browse files
authored
InputDecorationTheme.isCollapsed doesn't work if InputDecoration.isCollapsed is not provided. (flutter#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 flutter#133144
1 parent 9e9aa81 commit dd1ee24

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

packages/flutter/lib/src/material/input_decorator.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,10 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
21692169
return border.copyWith(
21702170
borderSide: BorderSide(
21712171
color: _getDefaultM2BorderColor(themeData),
2172-
width: (decoration.isCollapsed || decoration.border == InputBorder.none || !decoration.enabled)
2172+
width: (
2173+
(decoration.isCollapsed ?? themeData.inputDecorationTheme.isCollapsed)
2174+
|| decoration.border == InputBorder.none
2175+
|| !decoration.enabled)
21732176
? 0.0
21742177
: isFocused ? 2.0 : 1.0,
21752178
),
@@ -2402,7 +2405,8 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
24022405

24032406
final EdgeInsets contentPadding;
24042407
final double floatingLabelHeight;
2405-
if (decoration.isCollapsed) {
2408+
if (decoration.isCollapsed
2409+
?? themeData.inputDecorationTheme.isCollapsed) {
24062410
floatingLabelHeight = 0.0;
24072411
contentPadding = decorationContentPadding ?? EdgeInsets.zero;
24082412
} else if (!border.isOutline) {
@@ -2430,7 +2434,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
24302434
final _Decorator decorator = _Decorator(
24312435
decoration: _Decoration(
24322436
contentPadding: contentPadding,
2433-
isCollapsed: decoration.isCollapsed,
2437+
isCollapsed: decoration.isCollapsed ?? themeData.inputDecorationTheme.isCollapsed,
24342438
floatingLabelHeight: floatingLabelHeight,
24352439
floatingLabelAlignment: decoration.floatingLabelAlignment!,
24362440
floatingLabelProgress: _floatingLabelAnimation.value,
@@ -2577,7 +2581,7 @@ class InputDecoration {
25772581
this.errorMaxLines,
25782582
this.floatingLabelBehavior,
25792583
this.floatingLabelAlignment,
2580-
this.isCollapsed = false,
2584+
this.isCollapsed,
25812585
this.isDense,
25822586
this.contentPadding,
25832587
this.prefixIcon,
@@ -2976,7 +2980,7 @@ class InputDecoration {
29762980
/// A collapsed decoration cannot have [labelText], [errorText], an [icon].
29772981
///
29782982
/// To create a collapsed input decoration, use [InputDecoration.collapsed].
2979-
final bool isCollapsed;
2983+
final bool? isCollapsed;
29802984

29812985
/// An icon that appears before the [prefix] or [prefixText] and before
29822986
/// the editable part of the text field, within the decoration's container.
@@ -3620,7 +3624,7 @@ class InputDecoration {
36203624
floatingLabelAlignment: floatingLabelAlignment ?? theme.floatingLabelAlignment,
36213625
isDense: isDense ?? theme.isDense,
36223626
contentPadding: contentPadding ?? theme.contentPadding,
3623-
isCollapsed: isCollapsed,
3627+
isCollapsed: isCollapsed ?? theme.isCollapsed,
36243628
iconColor: iconColor ?? theme.iconColor,
36253629
prefixStyle: prefixStyle ?? theme.prefixStyle,
36263630
prefixIconColor: prefixIconColor ?? theme.prefixIconColor,
@@ -3782,7 +3786,7 @@ class InputDecoration {
37823786
if (floatingLabelAlignment != null) 'floatingLabelAlignment: $floatingLabelAlignment',
37833787
if (isDense ?? false) 'isDense: $isDense',
37843788
if (contentPadding != null) 'contentPadding: $contentPadding',
3785-
if (isCollapsed) 'isCollapsed: $isCollapsed',
3789+
if (isCollapsed ?? false) 'isCollapsed: $isCollapsed',
37863790
if (prefixIcon != null) 'prefixIcon: $prefixIcon',
37873791
if (prefixIconColor != null) 'prefixIconColor: $prefixIconColor',
37883792
if (prefix != null) 'prefix: $prefix',

packages/flutter/test/material/input_decorator_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6570,4 +6570,25 @@ testWidgets('OutlineInputBorder with BorderRadius.zero should draw a rectangular
65706570
expect(find.byType(InputDecorator), findsOneWidget);
65716571
expect(tester.renderObject<RenderBox>(find.text('COUNTER')).size, Size.zero);
65726572
});
6573+
6574+
group('isCollapsed parameter works with themeData', () {
6575+
test('parameter is provided in InputDecorationTheme', () {
6576+
final InputDecoration decoration = const InputDecoration(
6577+
hintText: 'Hello, Flutter!',
6578+
).applyDefaults(const InputDecorationTheme(
6579+
isCollapsed: true,
6580+
));
6581+
6582+
expect(decoration.isCollapsed, true);
6583+
});
6584+
6585+
test('parameter is provided in InputDecoration', () {
6586+
final InputDecoration decoration = const InputDecoration(
6587+
isCollapsed: true,
6588+
hintText: 'Hello, Flutter!',
6589+
).applyDefaults(const InputDecorationTheme());
6590+
6591+
expect(decoration.isCollapsed, true);
6592+
});
6593+
});
65736594
}

0 commit comments

Comments
 (0)