setSize method

void setSize(
  1. int newWidth,
  2. int newHeight
)

Implementation

void setSize(int newWidth, int newHeight) {
  final newGrid = List.generate(
    newHeight,
    (_) => List.generate(newWidth, (_) => ' '),
  );
  for (int y = 0; y < _height && y < newHeight; y++) {
    for (int x = 0; x < _width && x < newWidth; x++) {
      newGrid[y][x] = _grid[y][x];
    }
  }
  for (int y = 0; y < _height; y++) {
    for (int x = 0; x < _width; x++) {
      _grid[y][x] = newGrid[y][x];
    }
  }
  _width = newWidth;
  _height = newHeight;
}