Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TextParser tries to modify unmodifiable list #9

Merged
merged 1 commit into from
May 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions lib/text_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ class TextParser extends StatelessWidget {
textSpan.recognizer))) {
return _optimizeTextspan(textSpan.children!.first);
}

final textSpanChildren = List<InlineSpan>.from(textSpan.children ?? []);

// if our child node is just blank, then append its child nodes one up
// so, we flatten the tree
{
final textSpanChildren = textSpan.children;
if (textSpanChildren != null) {
if (textSpanChildren.isNotEmpty) {
final optimizedChildren = <InlineSpan>[];
for (var child in textSpanChildren) {
child = _optimizeTextspan(child);
Expand All @@ -185,14 +187,13 @@ class TextParser extends StatelessWidget {
optimizedChildren.add(child);
}
}
textSpan.children!.clear();
textSpan.children!.addAll(optimizedChildren);
textSpanChildren.clear();
textSpanChildren.addAll(optimizedChildren);
}
}
// now we try to merge children together
{
final textSpanChildren = textSpan.children;
if (textSpanChildren != null) {
if (textSpanChildren.isNotEmpty) {
final optimizedChildren = <InlineSpan>[];
for (final child in textSpanChildren) {
final lastChild =
Expand All @@ -217,12 +218,23 @@ class TextParser extends StatelessWidget {
optimizedChildren.add(child);
}
}
textSpan.children!.clear();
textSpan.children!.addAll(optimizedChildren);
textSpanChildren.clear();
textSpanChildren.addAll(optimizedChildren);
}
}
// we don't care much about additional optimization for now
return textSpan;
return TextSpan(
Sorunome marked this conversation as resolved.
Show resolved Hide resolved
text: textSpan.text,
children: textSpanChildren,
style: textSpan.style,
recognizer: textSpan.recognizer,
mouseCursor: textSpan.mouseCursor,
onEnter: textSpan.onEnter,
onExit: textSpan.onExit,
semanticsLabel: textSpan.semanticsLabel,
locale: textSpan.locale,
spellOut: textSpan.spellOut,
);
}

InlineSpan _parseInlineChildNodes(
Expand Down