Skip to content

Commit 73daff1

Browse files
auto-submit[bot]auto-submit[bot]
andauthored
Reverts "Fix InputDecoration.floatingLabelBehavior is not inherited (flutter#170905)" (flutter#170994)
<!-- start_original_pr_link --> Reverts: flutter#170905 <!-- end_original_pr_link --> <!-- start_initiating_author --> Initiated by: goderbauer <!-- end_initiating_author --> <!-- start_revert_reason --> Reason for reverting: Analyzer failure: `The argument type 'InputDecorationTheme' can't be assigned to the parameter type 'InputDecorationThemeData?'. • packages/flutter/test/material/input_decorator_test.dart:2959:33 • argument_type_not_assignable` <!-- end_revert_reason --> <!-- start_original_pr_author --> Original PR Author: bleroux <!-- end_original_pr_author --> <!-- start_reviewers --> Reviewed By: {justinmc} <!-- end_reviewers --> <!-- start_revert_body --> This change reverts the following previous change: ## Description This PR fixes `InputDecoration.floatingLabelBehavior` logic to query ambient InputDecorationTheme.floatingLabelBehavior, previously it was ignored. ## Related Issue Fixes [InputDecorationTheme and IconTheme isn't fully inherited](flutter#71813) Will help to complete flutter#168981 ## Tests Adds 1 test <!-- end_revert_body --> Co-authored-by: auto-submit[bot] <flutter-engprod-team@google.com>
1 parent 6ebb7cf commit 73daff1

File tree

2 files changed

+25
-38
lines changed

2 files changed

+25
-38
lines changed

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

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,12 @@ class InputDecorator extends StatefulWidget {
19241924
/// Whether the label needs to get out of the way of the input, either by
19251925
/// floating or disappearing.
19261926
///
1927-
/// Will withdraw when not empty or when focused while enabled.
1928-
bool get _labelShouldWithdraw => !isEmpty || (isFocused && decoration.enabled);
1927+
/// Will withdraw when not empty, when focused while enabled, or when
1928+
/// floating behavior is [FloatingLabelBehavior.always].
1929+
bool get _labelShouldWithdraw =>
1930+
!isEmpty ||
1931+
(isFocused && decoration.enabled) ||
1932+
decoration.floatingLabelBehavior == FloatingLabelBehavior.always;
19291933

19301934
@override
19311935
State<InputDecorator> createState() => _InputDecoratorState();
@@ -1976,7 +1980,15 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
19761980
void initState() {
19771981
super.initState();
19781982

1979-
_floatingLabelController = AnimationController(duration: _kTransitionDuration, vsync: this);
1983+
final bool labelIsInitiallyFloating =
1984+
widget.decoration.floatingLabelBehavior != FloatingLabelBehavior.never &&
1985+
widget._labelShouldWithdraw;
1986+
1987+
_floatingLabelController = AnimationController(
1988+
duration: _kTransitionDuration,
1989+
vsync: this,
1990+
value: labelIsInitiallyFloating ? 1.0 : 0.0,
1991+
);
19801992
_floatingLabelController.addListener(_handleChange);
19811993
_floatingLabelAnimation = CurvedAnimation(
19821994
parent: _floatingLabelController,
@@ -1991,10 +2003,6 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
19912003
void didChangeDependencies() {
19922004
super.didChangeDependencies();
19932005
_effectiveDecoration = null;
1994-
1995-
final bool labelIsInitiallyFloating =
1996-
decoration.floatingLabelBehavior != FloatingLabelBehavior.never && labelShouldWithdraw;
1997-
_floatingLabelController.value = labelIsInitiallyFloating ? 1.0 : 0.0;
19982006
}
19992007

20002008
@override
@@ -2026,10 +2034,6 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
20262034
return decoration.floatingLabelBehavior != FloatingLabelBehavior.never;
20272035
}
20282036

2029-
bool get labelShouldWithdraw =>
2030-
widget._labelShouldWithdraw ||
2031-
decoration.floatingLabelBehavior == FloatingLabelBehavior.always;
2032-
20332037
@override
20342038
void didUpdateWidget(InputDecorator old) {
20352039
super.didUpdateWidget(old);
@@ -2041,7 +2045,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
20412045
widget.decoration.floatingLabelBehavior != old.decoration.floatingLabelBehavior;
20422046

20432047
if (widget._labelShouldWithdraw != old._labelShouldWithdraw || floatBehaviorChanged) {
2044-
if (_floatingLabelEnabled && labelShouldWithdraw) {
2048+
if (_floatingLabelEnabled && widget._labelShouldWithdraw) {
20452049
_floatingLabelController.forward();
20462050
} else {
20472051
_floatingLabelController.reverse();
@@ -2127,7 +2131,8 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
21272131
// floatingLabelBehavior isn't set to always, then the label appears where the
21282132
// hint would.
21292133
bool get _hasInlineLabel {
2130-
return !labelShouldWithdraw && (decoration.labelText != null || decoration.label != null);
2134+
return !widget._labelShouldWithdraw &&
2135+
(decoration.labelText != null || decoration.label != null);
21312136
}
21322137

21332138
// If the label is a floating placeholder, it's always shown.
@@ -2352,7 +2357,10 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
23522357
child: AnimatedDefaultTextStyle(
23532358
duration: _kTransitionDuration,
23542359
curve: _kTransitionCurve,
2355-
style: labelShouldWithdraw ? _getFloatingLabelStyle(themeData, defaults) : labelStyle,
2360+
style:
2361+
widget._labelShouldWithdraw
2362+
? _getFloatingLabelStyle(themeData, defaults)
2363+
: labelStyle,
23562364
child:
23572365
decoration.label ??
23582366
Text(decoration.labelText!, overflow: TextOverflow.ellipsis, textAlign: textAlign),
@@ -2368,13 +2376,13 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
23682376
// If at least two out of the three are visible, it needs semantics sort
23692377
// order.
23702378
final bool needsSemanticsSortOrder =
2371-
labelShouldWithdraw &&
2379+
widget._labelShouldWithdraw &&
23722380
(input != null ? (hasPrefix || hasSuffix) : (hasPrefix && hasSuffix));
23732381

23742382
final Widget? prefix =
23752383
hasPrefix
23762384
? _AffixText(
2377-
labelIsFloating: labelShouldWithdraw,
2385+
labelIsFloating: widget._labelShouldWithdraw,
23782386
text: decoration.prefixText,
23792387
style:
23802388
MaterialStateProperty.resolveAs(decoration.prefixStyle, materialState) ??
@@ -2388,7 +2396,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
23882396
final Widget? suffix =
23892397
hasSuffix
23902398
? _AffixText(
2391-
labelIsFloating: labelShouldWithdraw,
2399+
labelIsFloating: widget._labelShouldWithdraw,
23922400
text: decoration.suffixText,
23932401
style:
23942402
MaterialStateProperty.resolveAs(decoration.suffixStyle, materialState) ??

packages/flutter/test/material/input_decorator_test.dart

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,32 +2944,11 @@ void main() {
29442944
);
29452945

29462946
expect(getDecoratorRect(tester).size, const Size(800.0, 56.0));
2947-
// Label line height is forced to 1.0 and font size is 16.0,
2948-
// the label should be vertically centered (20 pixels above and below).
29492947
expect(getLabelRect(tester).top, 20.0);
29502948
expect(getLabelRect(tester).bottom, 36.0);
29512949
},
29522950
);
29532951

2954-
// Regression test for https://github.com/flutter/flutter/issues/71813.
2955-
testWidgets('Ambient theme floatingLabelBehavior is used', (WidgetTester tester) async {
2956-
const FloatingLabelBehavior floatingLabelBehavior = FloatingLabelBehavior.never;
2957-
await tester.pumpWidget(
2958-
buildInputDecorator(
2959-
inputDecorationTheme: const InputDecorationTheme(
2960-
floatingLabelBehavior: floatingLabelBehavior,
2961-
),
2962-
decoration: const InputDecoration(label: customLabel),
2963-
),
2964-
);
2965-
2966-
expect(getDecoratorRect(tester).size, const Size(800.0, 56.0));
2967-
// Label line height is forced to 1.0 and font size is 16.0,
2968-
// the label should be vertically centered (20 pixels above and below).
2969-
expect(getCustomLabelRect(tester).top, 20.0);
2970-
expect(getCustomLabelRect(tester).bottom, 36.0);
2971-
});
2972-
29732952
testWidgets('Floating label animation duration and curve', (WidgetTester tester) async {
29742953
Future<void> pumpInputDecorator({required bool isFocused}) async {
29752954
return tester.pumpWidget(

0 commit comments

Comments
 (0)