endEvent static method

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

ends a timed event returns error or success message

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<Object> args = [];

  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) {
    args.add(options['segmentation']!);
  }

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

  return result;
}