From 533c6b29b49cab38fddd2cf407d421d1b45ce9d1 Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Wed, 1 Jul 2020 22:33:02 -0700 Subject: [PATCH] Show hint when label is floating (#60394) --- .../lib/src/material/input_decorator.dart | 11 ++++++++--- .../test/material/input_decorator_test.dart | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index af84401c38..fefa0add59 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -2086,9 +2086,14 @@ class _InputDecoratorState extends State with TickerProviderStat } // True if the label will be shown and the hint will not. - // If we're not focused, there's no value, and labelText was provided, - // then the label appears where the hint would. - bool get _hasInlineLabel => !widget._labelShouldWithdraw && decoration.labelText != null; + // If we're not focused, there's no value, labelText was provided, and + // floatingLabelBehavior isn't set to always, then the label appears where the + // hint would. + bool get _hasInlineLabel { + return !widget._labelShouldWithdraw + && decoration.labelText != null + && decoration.floatingLabelBehavior != FloatingLabelBehavior.always; + } // If the label is a floating placeholder, it's always shown. bool get _shouldShowLabel => _hasInlineLabel || _floatingLabelEnabled; diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index cccbef6b7d..60ccab5363 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -4068,6 +4068,23 @@ void main() { expect(tester.getTopLeft(find.text('label')).dy, 20.0); }); + testWidgets('InputDecorator hint is displayed when floatingLabelBehavior is always', (WidgetTester tester) async { + await tester.pumpWidget( + buildInputDecorator( + // isFocused: false (default) + isEmpty: true, + decoration: const InputDecoration( + floatingLabelBehavior: FloatingLabelBehavior.always, + hintText: 'hint', + labelText: 'label', + ), + ), + ); + await tester.pumpAndSettle(); + + expect(getOpacity(tester, 'hint'), 1.0); + }); + testWidgets('InputDecorator floating label width scales when focused', (WidgetTester tester) async { final String longStringA = String.fromCharCodes(List.generate(200, (_) => 65)); final String longStringB = String.fromCharCodes(List.generate(200, (_) => 66));