setBounds method

void setBounds(
  1. Shape? bounds, {
  2. bool considerViewport = false,
})

Sets or clears the world bounds for the camera's viewfinder.

The bound is a Shape, given in the world coordinates. The viewfinder's position will be restricted to always remain inside this region.

When considerViewport is true none of the viewport can go outside of the bounds, when it is false only the viewfinder anchor is considered. Note that this option only works with Rectangle, RoundedRectangle and Circle shapes.

Implementation

void setBounds(Shape? bounds, {bool considerViewport = false}) {
  final boundedBehavior = viewfinder.firstChild<BoundedPositionBehavior>();
  final viewPortAwareBoundsBehavior =
      viewfinder.firstChild<ViewportAwareBoundsBehavior>();
  if (bounds == null) {
    boundedBehavior?.removeFromParent();
    viewPortAwareBoundsBehavior?.removeFromParent();
    return;
  }
  if (boundedBehavior == null) {
    viewfinder.add(
      BoundedPositionBehavior(bounds: bounds, priority: 1000),
    );
  } else {
    boundedBehavior.bounds = bounds;
  }
  if (considerViewport) {
    if (viewPortAwareBoundsBehavior == null) {
      viewfinder.add(
        ViewportAwareBoundsBehavior(boundsShape: bounds),
      );
    } else {
      viewPortAwareBoundsBehavior.boundsShape = bounds;
    }
  } else {
    viewPortAwareBoundsBehavior?.removeFromParent();
  }
}