applyWidgetRotation method

Widget applyWidgetRotation(
  1. BuildContext context,
  2. BaseNode node,
  3. Widget widget
)

Convenience method to handle widget rotation.

Takes into account margin and padding to figure out the origin of the rotation.

Implementation

Widget applyWidgetRotation(
    BuildContext context, BaseNode node, Widget widget) {
  final CodelesslyContext payload = context.read<CodelesslyContext>();
  // Get node's values.
  final List<ValueModel> nodeValues =
      payload.nodeValues[node.id]?.value ?? [];
  // Get local rotation value if it exists, else use node's rotation value.
  final int rotationDegrees = nodeValues
          .firstWhereOrNull((value) => value.name == 'rotationDegrees')
          ?.value
          .typedValue<int>() ??
      node.rotationDegrees;
  if (rotationDegrees == 0) return widget;
  return widget = Transform.rotate(
    angle: rotationDegrees * pi / 180,
    origin: Offset(
      (node.outerBoxGlobal.edgeLeft / 2) -
          (node.outerBoxGlobal.edgeRight / 2),
      (node.outerBoxGlobal.edgeTop / 2) -
          (node.outerBoxGlobal.edgeBottom / 2),
    ),
    child: widget,
  );
}