preparedManaCost method

List<Widget>? preparedManaCost({
  1. EdgeInsets? padding = const EdgeInsets.symmetric(horizontal: 1.5),
})

Returns a visual representation of the manaCost using SVGs for valid MTG symbols. Returns null if manaCost is null or it doesn't contain any valid MTG symbols.

Pass null to padding to avoid using any padding - otherwise the padding will default 1.5 on each horizontal side.

Implementation

List<Widget>? preparedManaCost({
  EdgeInsets? padding = const EdgeInsets.symmetric(horizontal: 1.5),
}) {
  if (manaCost == null) {
    return null;
  }
  final matches = MtgSymbol.regex.allMatches(manaCost!);
  if (matches.isEmpty) {
    return null;
  }
  final manaCostSymbols = <Widget>[];
  for (final match in matches) {
    final matchedSymbol = match.group(0);
    final mtgSymbol = mtgSymbology[matchedSymbol];
    if (mtgSymbol == null) {
      throw ArgumentError.value(
        matchedSymbol,
        'matchedSymbol',
        'Unexpected MTG symbol',
      );
    }
    final svg = mtgSymbol.toSvg();
    manaCostSymbols.add(
      padding == null ? svg : Padding(padding: padding, child: svg),
    );
  }
  return manaCostSymbols;
}