toOffset method

Offset? toOffset({
  1. void onError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

Implementation

Offset? toOffset({
  void Function(Object error, StackTrace stackTrace)? onError,
}) {
  try {
    final renderBox = currentContext?.findRenderObject() as RenderBox?;
    if (renderBox == null) return null;
    Offset offset = renderBox
        .localToGlobal(Offset.zero)
        .translate(renderBox.size.width / 2, renderBox.size.height / 2);
    return offset;
  } catch (e, stack) {
    if (onError != null) {
      onError(e, stack);
    }
    return null;
  }
}