Skip to content

Commit

Permalink
fix: fix text overflow on long text (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip Pramanik authored Aug 11, 2024
1 parent bfba879 commit 5a8e37e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 35 deletions.
49 changes: 26 additions & 23 deletions lib/src/typethis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,29 +326,32 @@ class _TypeThisState extends State<TypeThis> {
}
}

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,
);
}
}
41 changes: 29 additions & 12 deletions test/typethis_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void main() {
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
expect(
richTextWidget.text.toPlainText(),
equals(testString.substring(0, 2)),
contains(testString.substring(0, 2)),
);
},
);
Expand All @@ -98,7 +98,7 @@ void main() {
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
expect(
richTextWidget.text.toPlainText(),
equals(testString.substring(0, 5)),
contains(testString.substring(0, 5)),
);
},
);
Expand All @@ -123,7 +123,7 @@ void main() {
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
expect(
richTextWidget.text.toPlainText(),
equals(testString.substring(0, 7)),
contains(testString.substring(0, 7)),
);
},
);
Expand All @@ -141,7 +141,7 @@ void main() {
expect(finder, findsOneWidget);

final richTextWidget = widgetTester.firstWidget<RichText>(finder);
expect(richTextWidget.text.toPlainText(), equals(''));
expect(richTextWidget.text.toPlainText(), contains(''));
},
);

Expand All @@ -158,7 +158,7 @@ void main() {
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
expect(
richTextWidget.text.toPlainText(),
equals(testString.substring(0, 3)),
contains(testString.substring(0, 3)),
);
},
);
Expand All @@ -175,7 +175,7 @@ void main() {
expect(finder, findsOneWidget);

final richTextWidget = widgetTester.firstWidget<RichText>(finder);
expect(richTextWidget.text.toPlainText(), equals(testString));
expect(richTextWidget.text.toPlainText(), contains(testString));
},
);
});
Expand All @@ -202,7 +202,7 @@ void main() {
expect(finder, findsOneWidget);

final richTextWidget = widgetTester.firstWidget<RichText>(finder);
expect(richTextWidget.text.toPlainText(), equals(''));
expect(richTextWidget.text.toPlainText(), contains(''));
},
);

Expand All @@ -219,7 +219,7 @@ void main() {
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
expect(
richTextWidget.text.toPlainText(),
equals(testString.substring(0, 3)),
contains(testString.substring(0, 3)),
);

expect(
Expand All @@ -241,7 +241,7 @@ void main() {
expect(finder, findsOneWidget);

final richTextWidget = widgetTester.firstWidget<RichText>(finder);
expect(richTextWidget.text.toPlainText(), equals(testString));
expect(richTextWidget.text.toPlainText(), contains(testString));

expect(find.text(testString, findRichText: true), findsOne);
},
Expand Down Expand Up @@ -314,9 +314,6 @@ void main() {

final blinkingCursorFinder = find.byType(BlinkingCursor);
expect(blinkingCursorFinder, findsNothing);

final sizedBoxFinder = find.byType(SizedBox);
expect(sizedBoxFinder, findsOneWidget);
},
);

Expand All @@ -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<RichText>(finder);
expect(richTextWidget.text.toPlainText(), contains(longString));

expect(find.byType(BlinkingCursor), findsOneWidget);
});
});
});
}

0 comments on commit 5a8e37e

Please sign in to comment.