forRectMaybeOf static method

DragBoundaryDelegate<Rect>? forRectMaybeOf(
  1. BuildContext context, {
  2. bool useGlobalPosition = true,
})

Retrieve the DragBoundary from the nearest ancestor to get its DragBoundaryDelegate of Rect.

The useGlobalPosition specifies whether to retrieve the DragBoundaryDelegate of type Rect in global coordinates. If false, the local coordinates of the boundary are used. Defaults to true.

returns null if not ancestor is found.

Implementation

static DragBoundaryDelegate<Rect>? forRectMaybeOf(
  BuildContext context, {
  bool useGlobalPosition = true,
}) {
  final InheritedElement? element =
      context.getElementForInheritedWidgetOfExactType<DragBoundary>();
  if (element == null) {
    return null;
  }
  final RenderBox? rb = element.findRenderObject() as RenderBox?;
  assert(rb != null && rb.hasSize, 'DragBoundary is not available');
  final Rect boundary =
      useGlobalPosition
          ? Rect.fromPoints(
            rb!.localToGlobal(Offset.zero),
            rb.localToGlobal(rb.size.bottomRight(Offset.zero)),
          )
          : Offset.zero & rb!.size;
  return _DragBoundaryDelegateForRect(boundary);
}