attach method

  1. @override
void attach(
  1. PipelineOwner owner
)
override

Mark this render object as attached to the given owner.

Typically called only from the parent's attach method, and by the owner to mark the root of a tree as attached.

Subclasses with children should override this method to attach all their children to the same owner after calling the inherited method, as in super.attach(owner).

Implementation

@override
void attach(PipelineOwner owner) {
  super.attach(owner);
  _leftDrag = HorizontalDragGestureRecognizer(debugOwner: this)
    ..onStart = (DragStartDetails details) {
      _isDraggingLeft = true;

      // Calculate where the mouse is relative to the exact visual line of the divider.
      // This prevents the divider from instantly jumping to the mouse center if the user
      // grabbed the slop edge. By subtracting physical X from mouse X, we get the offset.
      final Offset localPos = globalToLocal(details.globalPosition);
      _leftDragGrabOffset = localPos.dx - _leftDividerX;

      markNeedsPaint();
    }
    ..onUpdate = (DragUpdateDetails details) {
      if (!hasSize) {
        return;
      }

      final Offset localPos = globalToLocal(details.globalPosition);

      // Target where the divider *should* go by removing the initial grab offset.
      final double desiredLeftWidth = localPos.dx - _leftDragGrabOffset;

      final double currentRightWidth = childForSlot(DesktopPaneSlot.right)?.size.width ?? 0.0;
      final double maxLeft = size.width - _minContentWidth - currentRightWidth;

      leftPaneWidth = math.min(maxLeft, desiredLeftWidth);
    }
    ..onEnd = (_) {
      _isDraggingLeft = false;
      markNeedsPaint();
    }
    ..onCancel = () {
      _isDraggingLeft = false;
      markNeedsPaint();
    };

  _rightDrag = HorizontalDragGestureRecognizer(debugOwner: this)
    ..onStart = (DragStartDetails details) {
      _isDraggingRight = true;

      final Offset localPos = globalToLocal(details.globalPosition);
      _rightDragGrabOffset = localPos.dx - _rightDividerX;

      markNeedsPaint();
    }
    ..onUpdate = (DragUpdateDetails details) {
      if (!hasSize) {
        return;
      }

      final Offset localPos = globalToLocal(details.globalPosition);

      // 1. Calculate where the right divider *should* go.
      final double desiredDividerX = localPos.dx - _rightDragGrabOffset;

      // 2. Map that absolute X coordinate backward into the width of the right pane.
      final double desiredRightWidth = size.width - desiredDividerX;

      final double currentLeftWidth = childForSlot(DesktopPaneSlot.left)?.size.width ?? 0.0;
      final double maxRight = size.width - _minContentWidth - currentLeftWidth;

      rightPaneWidth = math.min(maxRight, desiredRightWidth);
    }
    ..onEnd = (_) {
      _isDraggingRight = false;
      markNeedsPaint();
    }
    ..onCancel = () {
      _isDraggingRight = false;
      markNeedsPaint();
    };
}