handleNativeEvent method
void
handleNativeEvent()
override
Handle an event from native code
Implementation
@override
void handleNativeEvent(
String viewId, String eventType, Map<String, dynamic> eventData) {
// First try to find a specific callback for this view and event
final callback = _eventCallbacks[viewId]?[eventType];
if (callback != null) {
try {
// Handle parameter count mismatch by checking function parameters
final Function func = callback;
if (func is Function()) {
func();
} else if (func is Function(Map<String, dynamic>)) {
func(eventData);
} else {
Function.apply(callback, [], {});
}
return;
} catch (e) {
debugPrint('Error executing callback: $e');
}
}
// If no specific callback found, use the global event handler as fallback
if (_eventHandler != null) {
try {
_eventHandler!(viewId, eventType, eventData);
} catch (e) {
debugPrint('Error executing global event handler: $e');
}
}
}