execute method
Implementation
@override
Future<Map<String, dynamic>> execute(List arguments, elementMap) async {
int defaultDoubleTapDuration = 200;
int defaultLongPressDuration = 1000;
// x and y coordinates to perform the click action
RxElement? element = arguments.isNotEmpty ? elementMap[arguments[0]] : null;
String anchor = arguments[1];
var left = element?.properties['ScreenX']?.toDouble();
var top = element?.properties['ScreenY']?.toDouble();
var width = element?.properties['Width']?.toDouble();
var height = element?.properties['Height']?.toDouble();
var coordinatesFromAnchor = [-1.0, -1.0];
if (element?.element is StatefulElement) {
var widget = (element!.element as StatefulElement).widget;
if (widget is Slider) {
coordinatesFromAnchor = setValuesOfSliderFromAnchor(
anchor, left, top, width, height, widget);
} else {
coordinatesFromAnchor =
resolveCoordinatesFromAnchor(anchor, left, top, width, height);
}
} else {
coordinatesFromAnchor =
resolveCoordinatesFromAnchor(anchor, left, top, width, height);
}
if (coordinatesFromAnchor[0] == -1 || coordinatesFromAnchor[1] == -1) {
return {'success': true, 'x': -1, 'y': -1};
}
double x = coordinatesFromAnchor[0];
double y = coordinatesFromAnchor[1];
// Simulate the gesture as specified in arguments
bool isLongPress = arguments.length > 2 && arguments[2] == true;
int longPressDuration =
arguments.length > 3 && arguments[3] > 0 ? arguments[3] : defaultLongPressDuration;
bool isDoubleTouch = (!isLongPress && longPressDuration == 2) ? true : false;
// Simulate the gesture
pointerDown(x, y);
if (isLongPress) {
// Wait for the duration to simulate a long press
await Future.delayed(Duration(milliseconds: longPressDuration));
}
pointerUp(x, y);
if (isDoubleTouch) {
// Wait for the duration to simulate the double tab
await Future.delayed(Duration(milliseconds: defaultDoubleTapDuration));
pointerDown(x, y);
pointerUp(x, y);
}
return {'success': true, 'x': x, 'y': y};
}