buildGridFromPattern method

Grid? buildGridFromPattern(
  1. Grid? grid,
  2. String? patternName
)

Modifies grid according to pattern identified by patternName For built-in patterns, check out PatternSet

Implementation

Grid? buildGridFromPattern(Grid? grid, String? patternName) {
  /// Retrieve from PatternSet
  Pattern? pattern = patternSet.firstWhere((p) => p.getName() == patternName);

  /// Modifies grid according to pattern, replacing clues with empty cells
  String _patrow = "";
  for (int row = 0; row < 9; row++) {
    _patrow = pattern.getMap()![row]!.replaceAll(' ', '');

    for (int col = 0; col < 9; col++) {
      if (_patrow.codeUnitAt(col) != HOLDER_CODE) {
        grid!.matrix()![row][col].clear();
      }
    }
  }

  return grid;
}