preparedOracleText method
Returns a visual representation of the oracleText using SVGs for valid
MTG symbols.
Returns null
if oracleText is null
.
Implementation
TextSpan? preparedOracleText() {
if (oracleText == null) {
return null;
}
final matches = MtgSymbol.regex.allMatches(oracleText!);
if (matches.isEmpty) {
return TextSpan(text: oracleText);
}
final children = <InlineSpan>[];
int lastIndex = 0;
for (final match in matches) {
children.add(
TextSpan(text: oracleText!.substring(lastIndex, match.start)),
);
final matchedSymbol = match.group(0);
final mtgSymbol = mtgSymbology[matchedSymbol];
if (mtgSymbol == null) {
throw ArgumentError.value(
matchedSymbol,
'matchedSymbol',
'Unexpected MTG symbol',
);
}
children.add(WidgetSpan(child: mtgSymbol.toSvg()));
lastIndex = match.end;
}
children.add(TextSpan(text: oracleText!.substring(lastIndex)));
return TextSpan(children: children);
}