From 5a8e37ec62d66a0469a50375c9a5ccef0e462052 Mon Sep 17 00:00:00 2001 From: Sandip Pramanik Date: Mon, 12 Aug 2024 01:30:54 +0530 Subject: [PATCH] fix: fix text overflow on long text (#10) --- lib/src/typethis.dart | 49 ++++++++++++++++++++++------------------- test/typethis_test.dart | 41 ++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 35 deletions(-) diff --git a/lib/src/typethis.dart b/lib/src/typethis.dart index 2efb6a3..e8154e5 100644 --- a/lib/src/typethis.dart +++ b/lib/src/typethis.dart @@ -326,29 +326,32 @@ class _TypeThisState extends State { } } - return Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text.rich( - TextSpan(children: [...widgets]), - textAlign: widget.textAlign ?? defaultTextStyle.textAlign, - style: defaultTextStyle.style.merge(widget.style), - strutStyle: widget.strutStyle, - textDirection: widget.textDirection, - locale: widget.locale, - softWrap: widget.softWrap ?? defaultTextStyle.softWrap, - overflow: widget.overflow, - textScaler: textScaler, - maxLines: widget.maxLines, - semanticsLabel: widget.semanticsLabel, - textWidthBasis: widget.textWidthBasis, - textHeightBehavior: widget.textHeightBehavior, - selectionColor: widget.selectionColor, - ), - widget.showBlinkingCursor - ? BlinkingCursor(cursorText: widget.cursorText) - : const SizedBox.shrink(), - ], + return Text.rich( + TextSpan( + children: [ + ...widgets, + widget.showBlinkingCursor + ? WidgetSpan( + child: BlinkingCursor( + cursorText: widget.cursorText, + ), + ) + : const TextSpan(), + ], + ), + textAlign: widget.textAlign ?? defaultTextStyle.textAlign, + style: defaultTextStyle.style.merge(widget.style), + strutStyle: widget.strutStyle, + textDirection: widget.textDirection, + locale: widget.locale, + softWrap: widget.softWrap ?? defaultTextStyle.softWrap, + overflow: widget.overflow, + textScaler: textScaler, + maxLines: widget.maxLines, + semanticsLabel: widget.semanticsLabel, + textWidthBasis: widget.textWidthBasis, + textHeightBehavior: widget.textHeightBehavior, + selectionColor: widget.selectionColor, ); } } diff --git a/test/typethis_test.dart b/test/typethis_test.dart index f73aa80..a1ba135 100644 --- a/test/typethis_test.dart +++ b/test/typethis_test.dart @@ -76,7 +76,7 @@ void main() { final richTextWidget = widgetTester.firstWidget(finder); expect( richTextWidget.text.toPlainText(), - equals(testString.substring(0, 2)), + contains(testString.substring(0, 2)), ); }, ); @@ -98,7 +98,7 @@ void main() { final richTextWidget = widgetTester.firstWidget(finder); expect( richTextWidget.text.toPlainText(), - equals(testString.substring(0, 5)), + contains(testString.substring(0, 5)), ); }, ); @@ -123,7 +123,7 @@ void main() { final richTextWidget = widgetTester.firstWidget(finder); expect( richTextWidget.text.toPlainText(), - equals(testString.substring(0, 7)), + contains(testString.substring(0, 7)), ); }, ); @@ -141,7 +141,7 @@ void main() { expect(finder, findsOneWidget); final richTextWidget = widgetTester.firstWidget(finder); - expect(richTextWidget.text.toPlainText(), equals('')); + expect(richTextWidget.text.toPlainText(), contains('')); }, ); @@ -158,7 +158,7 @@ void main() { final richTextWidget = widgetTester.firstWidget(finder); expect( richTextWidget.text.toPlainText(), - equals(testString.substring(0, 3)), + contains(testString.substring(0, 3)), ); }, ); @@ -175,7 +175,7 @@ void main() { expect(finder, findsOneWidget); final richTextWidget = widgetTester.firstWidget(finder); - expect(richTextWidget.text.toPlainText(), equals(testString)); + expect(richTextWidget.text.toPlainText(), contains(testString)); }, ); }); @@ -202,7 +202,7 @@ void main() { expect(finder, findsOneWidget); final richTextWidget = widgetTester.firstWidget(finder); - expect(richTextWidget.text.toPlainText(), equals('')); + expect(richTextWidget.text.toPlainText(), contains('')); }, ); @@ -219,7 +219,7 @@ void main() { final richTextWidget = widgetTester.firstWidget(finder); expect( richTextWidget.text.toPlainText(), - equals(testString.substring(0, 3)), + contains(testString.substring(0, 3)), ); expect( @@ -241,7 +241,7 @@ void main() { expect(finder, findsOneWidget); final richTextWidget = widgetTester.firstWidget(finder); - expect(richTextWidget.text.toPlainText(), equals(testString)); + expect(richTextWidget.text.toPlainText(), contains(testString)); expect(find.text(testString, findRichText: true), findsOne); }, @@ -314,9 +314,6 @@ void main() { final blinkingCursorFinder = find.byType(BlinkingCursor); expect(blinkingCursorFinder, findsNothing); - - final sizedBoxFinder = find.byType(SizedBox); - expect(sizedBoxFinder, findsOneWidget); }, ); @@ -335,6 +332,26 @@ void main() { expect(sizedBoxFinder, findsNothing); }, ); + + testWidgets('renders long text', (widgetTester) async { + widgetTester.view.physicalSize = const Size(100, 700); + + const longString = 'A very very very very very long piece of string'; + await widgetTester.pumpApp( + buildSubject( + string: longString, + showBlinkingCursor: true, + ), + ); + await widgetTester.pump(const Duration(seconds: 7)); + + final finder = find.byType(RichText); + + final richTextWidget = widgetTester.firstWidget(finder); + expect(richTextWidget.text.toPlainText(), contains(longString)); + + expect(find.byType(BlinkingCursor), findsOneWidget); + }); }); }); }