From eddba97d9ae5ab78f4a63a7b74e976f93693a5de Mon Sep 17 00:00:00 2001 From: Mehmet Fidanboylu Date: Tue, 28 Apr 2020 10:44:03 -0700 Subject: [PATCH] Fix behavior change due to incorrect initial floating setting (#55651) --- .../flutter/lib/src/material/input_decorator.dart | 6 ++++-- .../test/material/input_decorator_test.dart | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 26cf16ff79..b08d6ebc01 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -1915,8 +1915,10 @@ class _InputDecoratorState extends State with TickerProviderStat super.initState(); final bool labelIsInitiallyFloating = widget.decoration.floatingLabelBehavior == FloatingLabelBehavior.always - // ignore: deprecated_member_use_from_same_package - || (widget.decoration.hasFloatingPlaceholder && widget._labelShouldWithdraw); + || (widget.decoration.floatingLabelBehavior != FloatingLabelBehavior.never && + // ignore: deprecated_member_use_from_same_package + widget.decoration.hasFloatingPlaceholder && + widget._labelShouldWithdraw); _floatingLabelController = AnimationController( duration: _kTransitionDuration, diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index 66e9b6cd75..7063f98afd 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -3910,4 +3910,18 @@ void main() { expect(tester.getTopLeft(find.text('label')).dy, -4.0); }); + testWidgets('InputDecorator floating label obeys floatingLabelBehavior', (WidgetTester tester) async { + await tester.pumpWidget( + buildInputDecorator( + decoration: const InputDecoration( + labelText: 'label', + floatingLabelBehavior: FloatingLabelBehavior.never, + ), + ), + ); + + // Passing floating behavior never results in a dy offset of 20 + // because the label is not initially floating. + expect(tester.getTopLeft(find.text('label')).dy, 20.0); + }); }