endEvent static method

Future<String?> endEvent(
  1. Map<String, Object> options
)

Implementation

static Future<String?> endEvent(Map<String, Object> options) async {
  if (!_instance._countlyState.isInitialized) {
    String message = '"initWithConfig" must be called before "endEvent"';
    log('endEvent, $message', logLevel: LogLevel.ERROR);
    return message;
  }
  String eventKey = options['key'] != null ? options['key'].toString() : '';
  log('Calling "endEvent":[$eventKey]');
  List<String> args = [];
  var segmentation = {};

  if (eventKey.isEmpty) {
    String error = "endEvent, Can't end event with a null or empty key";
    log(error);
    return 'Error : $error';
  }
  args.add(eventKey);

  options['count'] ??= 1;
  args.add(options['count'].toString());

  options['sum'] ??= '0';
  args.add(options['sum'].toString());

  if (options['segmentation'] != null) {
    segmentation = options['segmentation'] as Map;
    segmentation.forEach((k, v) {
      args.add(k.toString());
      args.add(v.toString());
    });
  }

  final String? result = await _channel.invokeMethod('endEvent', <String, dynamic>{'data': json.encode(args)});

  return result;
}