snapToEdge method

void snapToEdge()

Implementation

void snapToEdge() {
  if (!isSnaping || _screenSize == Size.zero) return;

  final x = _position.offset.dx;
  final y = _position.offset.dy;

  final left = x;
  final right = _screenSize.width - (x + _settings.collapsedWidth);
  final top = y;
  final bottom =
      _screenSize.height -
      (y + _settings.collapsedHeight) -
      bottomSafePadding;

  final newX = left < right
      ? margin
      : _screenSize.width - _settings.collapsedWidth - margin;
  final newY = top < bottom
      ? margin
      : _screenSize.height -
            _settings.collapsedHeight -
            margin -
            bottomSafePadding;

  final newAnchor = top < bottom
      ? (left < right ? PipAnchor.topLeft : PipAnchor.topRight)
      : (left < right ? PipAnchor.bottomLeft : PipAnchor.bottomRight);

  _position = _position.copyWith(
    offset: Offset(newX, newY),
    anchor: newAnchor,
  );
  notify();
}