addEventListener method

int addEventListener(
  1. String eventName,
  2. dynamic callback(
    1. Map<String, dynamic>
    )
)

Add a Spline runtime event listener (e.g. mouseDown, mouseUp, start ...) Returns an integer id that can be used to remove a specific callback.

Implementation

int addEventListener(String eventName, Function(Map<String, dynamic>) callback) {
  final list = _eventListeners.putIfAbsent(eventName, () => []);
  list.add(callback);
  final id = ++_eventCallbackSerial;
  _callbackById[id] = callback;
  // Fire JS attach command (best-effort; scene may not be ready yet) - JS bridge will ignore duplicates.
  runJavaScript('window.SplineFlutterBridge?.addEventListener?.(${_jsString(eventName)});');
  return id;
}