changeDeviceId static method

Future<String?> changeDeviceId(
  1. String newDeviceID,
  2. bool onServer
)

Implementation

static Future<String?> changeDeviceId(String newDeviceID, bool onServer) async {
  if (!_instance._countlyState.isInitialized) {
    String message = '"initWithConfig" must be called before "changeDeviceId"';
    log('changeDeviceId, $message', logLevel: LogLevel.ERROR);
    return message;
  }
  log('Calling "changeDeviceId":[$newDeviceID] with onServer:[$onServer]');
  if (newDeviceID.isEmpty) {
    String error = 'changeDeviceId, deviceId cannot be null or empty';
    log(error);
    return 'Error : $error';
  }
  List<String> args = [];
  String onServerString;
  if (onServer == false) {
    onServerString = '0';
  } else {
    onServerString = '1';
  }
  args.add(newDeviceID);
  args.add(onServerString);

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

  return result;
}