Skip to content

Commit 9cea071

Browse files
committed
Fix Stack Overflow error when using before and afters
1 parent 0874d55 commit 9cea071

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/html_parser.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,17 @@ class HtmlParser extends StatelessWidget {
572572
/// the list of the trees children according to the `before` and `after` Style
573573
/// properties.
574574
static StyledElement _processBeforesAndAfters(StyledElement tree) {
575-
if (tree.style.before != null) {
575+
if (tree.style.before != null && tree.children.isNotEmpty) {
576576
tree.children.insert(
577-
0, TextContentElement(text: tree.style.before, style: tree.style));
577+
0, new TextContentElement(text: tree.style.before, style: tree.style.copyWith(beforeAfterNull: true, display: Display.INLINE)));
578578
}
579579
if (tree.style.after != null) {
580580
tree.children
581-
.add(TextContentElement(text: tree.style.after, style: tree.style));
582-
} else {
583-
tree.children.forEach(_processBeforesAndAfters);
581+
.add(TextContentElement(text: tree.style.after, style: tree.style.copyWith(beforeAfterNull: true, display: Display.INLINE)));
584582
}
583+
584+
tree.children.forEach(_processBeforesAndAfters);
585+
585586
return tree;
586587
}
587588

lib/style.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ class Style {
348348
Border? border,
349349
Alignment? alignment,
350350
String? markerContent,
351+
bool? beforeAfterNull,
351352
}) {
352353
return Style(
353354
backgroundColor: backgroundColor ?? this.backgroundColor,
@@ -377,8 +378,8 @@ class Style {
377378
whiteSpace: whiteSpace ?? this.whiteSpace,
378379
width: width ?? this.width,
379380
wordSpacing: wordSpacing ?? this.wordSpacing,
380-
before: before ?? this.before,
381-
after: after ?? this.after,
381+
before: beforeAfterNull == true ? null : before ?? this.before,
382+
after: beforeAfterNull == true ? null : after ?? this.after,
382383
border: border ?? this.border,
383384
alignment: alignment ?? this.alignment,
384385
markerContent: markerContent ?? this.markerContent,

0 commit comments

Comments
 (0)