Skip to content

Commit 5a8e37e

Browse files
author
Sandip Pramanik
authored
fix: fix text overflow on long text (#10)
1 parent bfba879 commit 5a8e37e

File tree

2 files changed

+55
-35
lines changed

2 files changed

+55
-35
lines changed

lib/src/typethis.dart

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -326,29 +326,32 @@ class _TypeThisState extends State<TypeThis> {
326326
}
327327
}
328328

329-
return Row(
330-
mainAxisSize: MainAxisSize.min,
331-
children: [
332-
Text.rich(
333-
TextSpan(children: [...widgets]),
334-
textAlign: widget.textAlign ?? defaultTextStyle.textAlign,
335-
style: defaultTextStyle.style.merge(widget.style),
336-
strutStyle: widget.strutStyle,
337-
textDirection: widget.textDirection,
338-
locale: widget.locale,
339-
softWrap: widget.softWrap ?? defaultTextStyle.softWrap,
340-
overflow: widget.overflow,
341-
textScaler: textScaler,
342-
maxLines: widget.maxLines,
343-
semanticsLabel: widget.semanticsLabel,
344-
textWidthBasis: widget.textWidthBasis,
345-
textHeightBehavior: widget.textHeightBehavior,
346-
selectionColor: widget.selectionColor,
347-
),
348-
widget.showBlinkingCursor
349-
? BlinkingCursor(cursorText: widget.cursorText)
350-
: const SizedBox.shrink(),
351-
],
329+
return Text.rich(
330+
TextSpan(
331+
children: [
332+
...widgets,
333+
widget.showBlinkingCursor
334+
? WidgetSpan(
335+
child: BlinkingCursor(
336+
cursorText: widget.cursorText,
337+
),
338+
)
339+
: const TextSpan(),
340+
],
341+
),
342+
textAlign: widget.textAlign ?? defaultTextStyle.textAlign,
343+
style: defaultTextStyle.style.merge(widget.style),
344+
strutStyle: widget.strutStyle,
345+
textDirection: widget.textDirection,
346+
locale: widget.locale,
347+
softWrap: widget.softWrap ?? defaultTextStyle.softWrap,
348+
overflow: widget.overflow,
349+
textScaler: textScaler,
350+
maxLines: widget.maxLines,
351+
semanticsLabel: widget.semanticsLabel,
352+
textWidthBasis: widget.textWidthBasis,
353+
textHeightBehavior: widget.textHeightBehavior,
354+
selectionColor: widget.selectionColor,
352355
);
353356
}
354357
}

test/typethis_test.dart

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void main() {
7676
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
7777
expect(
7878
richTextWidget.text.toPlainText(),
79-
equals(testString.substring(0, 2)),
79+
contains(testString.substring(0, 2)),
8080
);
8181
},
8282
);
@@ -98,7 +98,7 @@ void main() {
9898
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
9999
expect(
100100
richTextWidget.text.toPlainText(),
101-
equals(testString.substring(0, 5)),
101+
contains(testString.substring(0, 5)),
102102
);
103103
},
104104
);
@@ -123,7 +123,7 @@ void main() {
123123
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
124124
expect(
125125
richTextWidget.text.toPlainText(),
126-
equals(testString.substring(0, 7)),
126+
contains(testString.substring(0, 7)),
127127
);
128128
},
129129
);
@@ -141,7 +141,7 @@ void main() {
141141
expect(finder, findsOneWidget);
142142

143143
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
144-
expect(richTextWidget.text.toPlainText(), equals(''));
144+
expect(richTextWidget.text.toPlainText(), contains(''));
145145
},
146146
);
147147

@@ -158,7 +158,7 @@ void main() {
158158
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
159159
expect(
160160
richTextWidget.text.toPlainText(),
161-
equals(testString.substring(0, 3)),
161+
contains(testString.substring(0, 3)),
162162
);
163163
},
164164
);
@@ -175,7 +175,7 @@ void main() {
175175
expect(finder, findsOneWidget);
176176

177177
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
178-
expect(richTextWidget.text.toPlainText(), equals(testString));
178+
expect(richTextWidget.text.toPlainText(), contains(testString));
179179
},
180180
);
181181
});
@@ -202,7 +202,7 @@ void main() {
202202
expect(finder, findsOneWidget);
203203

204204
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
205-
expect(richTextWidget.text.toPlainText(), equals(''));
205+
expect(richTextWidget.text.toPlainText(), contains(''));
206206
},
207207
);
208208

@@ -219,7 +219,7 @@ void main() {
219219
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
220220
expect(
221221
richTextWidget.text.toPlainText(),
222-
equals(testString.substring(0, 3)),
222+
contains(testString.substring(0, 3)),
223223
);
224224

225225
expect(
@@ -241,7 +241,7 @@ void main() {
241241
expect(finder, findsOneWidget);
242242

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

246246
expect(find.text(testString, findRichText: true), findsOne);
247247
},
@@ -314,9 +314,6 @@ void main() {
314314

315315
final blinkingCursorFinder = find.byType(BlinkingCursor);
316316
expect(blinkingCursorFinder, findsNothing);
317-
318-
final sizedBoxFinder = find.byType(SizedBox);
319-
expect(sizedBoxFinder, findsOneWidget);
320317
},
321318
);
322319

@@ -335,6 +332,26 @@ void main() {
335332
expect(sizedBoxFinder, findsNothing);
336333
},
337334
);
335+
336+
testWidgets('renders long text', (widgetTester) async {
337+
widgetTester.view.physicalSize = const Size(100, 700);
338+
339+
const longString = 'A very very very very very long piece of string';
340+
await widgetTester.pumpApp(
341+
buildSubject(
342+
string: longString,
343+
showBlinkingCursor: true,
344+
),
345+
);
346+
await widgetTester.pump(const Duration(seconds: 7));
347+
348+
final finder = find.byType(RichText);
349+
350+
final richTextWidget = widgetTester.firstWidget<RichText>(finder);
351+
expect(richTextWidget.text.toPlainText(), contains(longString));
352+
353+
expect(find.byType(BlinkingCursor), findsOneWidget);
354+
});
338355
});
339356
});
340357
}

0 commit comments

Comments
 (0)