execute method

  1. @override
Future<Map<String, dynamic>> execute(
  1. List arguments,
  2. Map<int, RxElement> elementMap
)
override

Implementation

@override
Future<Map<String, dynamic>> execute(List arguments, Map<int, RxElement> elementMap) async {
  // Extract WebView and DOM element details
  RxElement? webViewElement = arguments.isNotEmpty ? elementMap[arguments[webViewIdIndex]] : null;

  if (webViewElement == null) {
    return {'success': false, 'message': 'WebView element not found'};
  }

  // Extract and validate parameters
  int domElementId = arguments.length > domElementIdIndex ? arguments[domElementIdIndex] : -1;
  // String location = arguments.length > locationIndex ? arguments[locationIndex] : '';
  bool isLongPress = arguments.length > longClickIndex ? arguments[longClickIndex] : false;
  int duration = arguments.length > durationIndex ? arguments[durationIndex] : defaultDuration;

  // Get x and y coordinates from the WebView element
  var valueX = webViewElement.properties['Left']?.toDouble() ?? 0.0;
  var valueY = webViewElement.properties['Top']?.toDouble() ?? 0.0;

  FlutterView view = WidgetsBinding.instance.platformDispatcher.views.first;
  var devicePixelRatio = view.devicePixelRatio;
  double x = valueX / devicePixelRatio;
  double y = valueY / devicePixelRatio;

  if (domElementId < 0) {
    // Simulate click on the DOM element
    // Simulate the gesture
    pointerDown(x, y);
    if (isLongPress) {
      // Wait for the duration to simulate a long press
      await Future.delayed(Duration(milliseconds: duration));
    }
    pointerUp(x, y);

    return {'success': true, 'x': x, 'y': y};
  } else {
    return {'success': false, 'message': 'Invalid DOM element ID'};
  }
}