From 6ec1c75ac76232c80018b104a72b0ec3e5d6480a Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Mon, 3 Jun 2024 15:03:06 -0700 Subject: [PATCH] Fixes multi line textfield hint text gets ellipsized (#148423) fixes https://github.com/flutter/flutter/issues/148353 --- .../lib/src/material/input_decorator.dart | 2 +- .../test/material/text_field_test.dart | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 66debd86eb..c673072358 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -2164,7 +2164,7 @@ class _InputDecoratorState extends State with TickerProviderStat hintText, style: hintStyle, textDirection: decoration.hintTextDirection, - overflow: hintStyle.overflow ?? TextOverflow.ellipsis, + overflow: hintStyle.overflow ?? (decoration.hintMaxLines == null ? null : TextOverflow.ellipsis), textAlign: textAlign, maxLines: decoration.hintMaxLines, ), diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index 516f4332e5..1f667d152e 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -1875,6 +1875,48 @@ void main() { expect(find.text('Paste'), findsOneWidget); }, skip: isContextMenuProvidedByPlatform); // [intended] only applies to platforms where we supply the context menu. + testWidgets('infinite multi-line text hint text is not ellipsized by default', (WidgetTester tester) async { + const String kLongString = + 'Enter your email Enter your email Enter your ' + 'email Enter your email Enter your email Enter ' + 'your email Enter your email'; + const double defaultLineHeight = 24; + await tester.pumpWidget(overlay( + child: const TextField( + maxLines: null, + decoration: InputDecoration( + labelText: 'Email', + hintText: kLongString, + ), + ), + )); + final Text hintText = tester.widget(find.text(kLongString)); + expect(hintText.overflow, isNull); + final RenderParagraph paragraph = tester.renderObject(find.text(kLongString)); + expect(paragraph.size.height > defaultLineHeight * 2, isTrue); + }); + + testWidgets('non-infinite multi-line hint text is ellipsized by default', (WidgetTester tester) async { + const String kLongString = + 'Enter your email Enter your email Enter your ' + 'email Enter your email Enter your email Enter ' + 'your email Enter your email'; + const double defaultLineHeight = 24; + await tester.pumpWidget(overlay( + child: const TextField( + maxLines: 2, + decoration: InputDecoration( + labelText: 'Email', + hintText: kLongString, + ), + ), + )); + final Text hintText = tester.widget(find.text(kLongString)); + expect(hintText.overflow, TextOverflow.ellipsis); + final RenderParagraph paragraph = tester.renderObject(find.text(kLongString)); + expect(paragraph.size.height < defaultLineHeight * 2 + precisionErrorTolerance, isTrue); + }); + testWidgets('Entering text hides selection handle caret', (WidgetTester tester) async { final TextEditingController controller = _textEditingController();