sendEvent method

Future<void> sendEvent(
  1. String eventName,
  2. Map<String, String> eventProperties
)

Sends an event with the specified eventName and eventProperties.

This method invokes the native method sendEvent.

Throws a PlatformException if the event sending fails.

eventName: The name of the event to send. eventProperties: A map of properties associated with the event.

Implementation

Future<void> sendEvent(
    String eventName, Map<String, String> eventProperties) async {
  if(Platform.isAndroid){
    try {
      await methodChannel.invokeMethod('sendEvent',
          {"eventName": eventName, "eventProperties": eventProperties});
    } on PlatformException catch (e) {
      print("Failed to send event: '${e.message}'.");
    }}
  else if(Platform.isIOS){
    try {

      // Sending the event name and properties to the iOS side
      await methodChannel.invokeMethod('sendEvent', {
        'eventName': eventName,
        'eventProperties': eventProperties,
      });
      print("Event Sent: $eventName");
    } on PlatformException catch (e) {
      print("Failed to send event: '${e.message}'.");
    }
  }
}