centerOnGridOffset method

void centerOnGridOffset(
  1. Offset gsOffset, {
  2. Duration? duration,
  3. bool animate = true,
})

Center the canvas so that the given grid-space offset is at the center of the viewport.

Implementation

void centerOnGridOffset(Offset gsOffset, {Duration? duration, bool animate = true}) {
  // if 2x scale you need to adjust lesser
  final newGsTopLeft = gsOffset + (canvasSize * (2 * scale)).toOffset();
  if (animate) {
    animateToOffsetAndScale(offset: newGsTopLeft, duration: duration, scale: _scale);
  } else {
    _gsTopLeftOffset = newGsTopLeft;
    markDirty();
  }
}