pinchGestureHelper static method

void pinchGestureHelper({
  1. required Widget? gesture,
  2. required String onType,
  3. Offset? offset,
  4. double? scale,
  5. Velocity? velocity,
  6. int fingers = 0,
})

Implementation

static void pinchGestureHelper(
    {required Widget? gesture,
    required String onType,
    Offset? offset,
    double? scale,
    Velocity? velocity,
    int fingers = 0}) async {
  if (gesture == null) {
    tlLogger.w('Warning: Gesture is null in pinchGestureHelper');
    return;
  }
  final int hashCode = gesture.hashCode;

  if (WidgetPath.containsKey(hashCode)) {
    final WidgetPath? wp = WidgetPath.getPath(hashCode);
    final BuildContext? context = wp!.context;
    final String gestureTarget = getGestureTarget(wp);
    final Map<String, dynamic> accessibility = checkForSemantics(wp);

    tlLogger.v(
        '${onType.toUpperCase()}: Gesture widget, context hash: ${context.hashCode}, widget hash: $hashCode');

    switch (onType) {
      case _onScaleStart:
        {
          final _Pinch pinch = _Pinch();
          pinch.startPosition = offset!;
          wp.addParameters(<String, dynamic>{'pinch': pinch});
          break;
        }
      case _onScaleUpdate:
        {
          if (wp.parameters.containsKey('pinch')) {
            final _Pinch pinch = wp.parameters['pinch'];
            pinch.updatePosition = offset!;
            pinch.scale = scale!;
            pinch.fingers = fingers;
          }
          break;
        }
      case _onScaleEnd:
        {
          if (wp.parameters.containsKey('pinch')) {
            final _Pinch pinch = wp.parameters['pinch'];
            pinch.fingers = fingers;
            final String direction = pinch.pinchResult();
            tlLogger.v(
                '--> Pinch, fingers: ${pinch.getMaxFingers}, direction: $direction');

            if (direction.isNotEmpty) {
              final Offset start = pinch.getStartPosition!;
              final Offset end = pinch.getUpdatePosition!;
              wp.parameters.clear();
              await PluginTealeaf.onTlGestureEvent(
                  gesture: 'pinch',
                  id: wp.widgetPath(),
                  target: gestureTarget,
                  data: <String, dynamic>{
                    'pointer1': {'dx': start.dx, 'dy': start.dy},
                    'pointer2': {'dx': end.dx, 'dy': end.dy},
                    'direction': direction,
                    'velocity': {
                      'dx': velocity?.pixelsPerSecond.dx,
                      'dy': velocity?.pixelsPerSecond.dy
                    },
                    ...accessibility,
                  },
                  layoutParameters: TlBinder.layoutParametersForGestures);
            }
          }
          break;
        }
      default:
        break;
    }
  } else {
    tlLogger.v(
        "ERROR: ${gesture.runtimeType.toString()} not found for hashcode: $hashCode");
  }
}