findAndUpdateWidgetPosition function

RenderBox findAndUpdateWidgetPosition({
  1. required GlobalKey<State<StatefulWidget>> widgetAnchor,
  2. required BuildContext context,
  3. required VSInterfaceData data,
})

Implementation

RenderBox findAndUpdateWidgetPosition({
  required GlobalKey widgetAnchor,
  required BuildContext context,
  required VSInterfaceData data,
}) {
  final renderBox =
      widgetAnchor.currentContext?.findRenderObject() as RenderBox;
  Offset position = renderBox.localToGlobal(getWidgetCenter(renderBox));

  final provider = VSNodeDataProvider.of(context);

  final newOffset =
      provider.applyViewPortTransfrom(position) - data.nodeData!.widgetOffset;

  if (newOffset != data.widgetOffset) {
    data.widgetOffset = newOffset;
    provider.updateOrCreateNodes([data.nodeData!], updateHistory: false);
  }

  return renderBox;
}