@@ -107,6 +107,8 @@ class TextLayoutService {
107
107
// *** THE MAIN MEASUREMENT PART *** //
108
108
// ********************************* //
109
109
110
+ final isLastSpan = spanIndex == spanCount - 1 ;
111
+
110
112
if (span is PlaceholderSpan ) {
111
113
if (currentLine.widthIncludingSpace + span.width <= constraints.width) {
112
114
// The placeholder fits on the current line.
@@ -119,6 +121,11 @@ class TextLayoutService {
119
121
}
120
122
currentLine.addPlaceholder (span);
121
123
}
124
+
125
+ if (isLastSpan) {
126
+ lines.add (currentLine.build ());
127
+ break ;
128
+ }
122
129
} else if (span is FlatTextSpan ) {
123
130
spanometer.currentSpan = span;
124
131
final LineBreakResult nextBreak = currentLine.findNextBreak (span.end);
@@ -219,17 +226,23 @@ class TextLayoutService {
219
226
minIntrinsicWidth = widthOfLastSegment;
220
227
}
221
228
229
+ // Max intrinsic width includes the width of trailing spaces.
230
+ if (maxIntrinsicWidth < currentLine.widthIncludingSpace) {
231
+ maxIntrinsicWidth = currentLine.widthIncludingSpace;
232
+ }
233
+
222
234
if (currentLine.end.isHard) {
223
- // Max intrinsic width includes the width of trailing spaces.
224
- if (maxIntrinsicWidth < currentLine.widthIncludingSpace) {
225
- maxIntrinsicWidth = currentLine.widthIncludingSpace;
226
- }
227
235
currentLine = currentLine.nextLine ();
228
236
}
229
237
230
238
// Only go to the next span if we've reached the end of this span.
231
- if (currentLine.end.index >= span.end && spanIndex < spanCount - 1 ) {
232
- span = paragraph.spans[++ spanIndex];
239
+ if (currentLine.end.index >= span.end) {
240
+ if (spanIndex < spanCount - 1 ) {
241
+ span = paragraph.spans[++ spanIndex];
242
+ } else {
243
+ // We reached the end of the last span in the paragraph.
244
+ break ;
245
+ }
233
246
}
234
247
}
235
248
}
@@ -632,7 +645,10 @@ class LineSegment {
632
645
double get widthOfTrailingSpace => widthIncludingSpace - width;
633
646
634
647
/// Whether this segment is made of only white space.
635
- bool get isSpaceOnly => start.index == end.indexWithoutTrailingSpaces;
648
+ ///
649
+ /// We rely on the [width] to determine this because relying on incides
650
+ /// doesn't work well for placeholders (they are zero-length strings).
651
+ bool get isSpaceOnly => width == 0 ;
636
652
}
637
653
638
654
/// Builds instances of [EngineLineMetrics] for the given [paragraph] .
0 commit comments