parsePlacement static method

GridPlacement parsePlacement(
  1. String value
)

Implementation

static GridPlacement parsePlacement(String value) {
  final String trimmed = value.trim();
  if (trimmed.isEmpty || trimmed.toLowerCase() == 'auto') {
    return const GridPlacement.auto();
  }

  final String lower = trimmed.toLowerCase();
  if (lower.startsWith('span')) {
    final String rest = trimmed.substring(4).trim();
    if (rest.isEmpty) return const GridPlacement.span(1);
    int? spanValue;
    for (final String token in rest.split(RegExp(r'\s+'))) {
      final int? parsed = int.tryParse(token);
      if (parsed != null && parsed > 0) {
        spanValue = parsed;
        break;
      }
    }
    if (spanValue != null) {
      return GridPlacement.span(spanValue);
    }
    return const GridPlacement.span(1);
  }

  final int? lineValue = int.tryParse(trimmed);
  if (lineValue != null) {
    // Grid line number 0 is invalid per CSS Grid and should be treated as 'auto'.
    if (lineValue == 0) {
      return const GridPlacement.auto();
    }
    return GridPlacement.line(lineValue);
  }

  final List<String> tokens = trimmed.split(RegExp(r'\s+'));
  if (tokens.length == 2) {
    final int? occurrence = int.tryParse(tokens[1]);
    if (occurrence != null && occurrence != 0 && isCustomIdent(tokens[0])) {
      return GridPlacement.named(
        tokens[0],
        occurrence: occurrence,
        explicitOccurrence: true,
      );
    }
  }

  if (isCustomIdent(trimmed)) {
    return GridPlacement.named(trimmed);
  }

  return const GridPlacement.auto();
}