addConnector method

SealdConnector addConnector(
  1. String connectorType,
  2. String connectorValue, {
  3. SealdPreValidationToken? preValidationToken,
})

Add a connector to the current identity. If no preValidationToken is given, the connector will need to be validated before use.

connectorType - The type of the connector to add. connectorValue - The value of the connector to add. preValidationToken - Given by your server to authorize the adding of a connector. Returns the created SealdConnector instance.

Implementation

SealdConnector addConnector(String connectorType, String connectorValue,
    {SealdPreValidationToken? preValidationToken}) {
  if (_closed) {
    throw SealdException(
        code: "INSTANCE_CLOSED",
        id: "FLUTTER_INSTANCE_CLOSED",
        description: "Instance already closed.");
  }
  final Pointer<Utf8> nativeConnectorType = connectorType.toNativeUtf8();
  final Pointer<Utf8> nativeConnectorValue = connectorValue.toNativeUtf8();
  final Pointer<NativeSealdPreValidationToken> nativePreValidationToken =
      preValidationToken?._toC() ?? nullptr;
  final Pointer<Pointer<NativeSealdConnector>> result =
      calloc<Pointer<NativeSealdConnector>>();
  final Pointer<Pointer<NativeSealdError>> err =
      calloc<Pointer<NativeSealdError>>();

  final int resultCode = _bindings.SealdSdk_AddConnector(
      _ptr.pointer(),
      nativeConnectorValue,
      nativeConnectorType,
      nativePreValidationToken,
      result,
      err);

  calloc.free(nativeConnectorType);
  calloc.free(nativeConnectorValue);
  _bindings.SealdPreValidationToken_Free(nativePreValidationToken);

  if (resultCode != 0) {
    calloc.free(result);
    throw SealdException._fromCPtr(err);
  } else {
    final SealdConnector connector = SealdConnector._fromC(result.value);
    calloc.free(result);
    calloc.free(err);
    return connector;
  }
}