parsePowerToughness function

TextSpan? parsePowerToughness(
  1. String? powerToughness
)

Parses a power/toughness string (e.g., "2/3", "*/4") and returns a TextSpan.

Returns null if the input is null or invalid.

Implementation

TextSpan? parsePowerToughness(String? powerToughness) {
  if (powerToughness == null) return null;

  final RegExp ptRegex = RegExp(r'([*\d]+|\*)/([*\d]+|\*)');
  RegExpMatch? match = ptRegex.firstMatch(powerToughness);
  if (match == null) {
    return TextSpan(text: powerToughness); // Fallback to plain text
  }

  String? power = match.group(1);
  String? toughness = match.group(2);
  return TextSpan(
    text: '$power / $toughness',
    style: const TextStyle(fontWeight: FontWeight.bold),
  );
}