generateLicenseKey static method

TaskHandler? generateLicenseKey({
  1. required String applicationId,
  2. String productId = ProductID.core,
  3. required void onComplete(
    1. GemError error,
    2. String hint
    ),
})

Generates a new license key for the provided application and product.

Requests a license key from the remote activation service for the given applicationId and optional productId. The operation is asynchronous and progress/results are delivered via the onComplete callback.

The generated license key is a UUID v4 string that uniquely identifies the license for activation purposes.

Parameters

  • applicationId: The application identifier for which the license key is created.
  • productId: The product identifier to bind the license to. Defaults to ProductID.core.
  • onComplete: Callback invoked when the generation finishes. The callback receives a GemError describing the result and a human-readable hint:

Returns

  • TaskHandler: A task handle to observe or cancel the operation when the request started successfully, otherwise null if the request could not be initiated.

Throws

  • May throw an exception if the platform call fails unexpectedly.

Also see:

  • activate - Activates a product using the supplied license key.
  • SdkSettings - Manage app tokens and other settings.

Implementation

static TaskHandler? generateLicenseKey({
  required final String applicationId,
  final String productId = ProductID.core,
  required final void Function(GemError error, String hint) onComplete,
}) {
  final EventDrivenProgressListener progListener =
      EventDrivenProgressListener();
  GemKitPlatform.instance.registerEventHandler(progListener.id, progListener);

  progListener.registerOnCompleteWithData((
    final int err,
    final String hint,
    final Map<dynamic, dynamic> json,
  ) {
    GemKitPlatform.instance.unregisterEventHandler(progListener.id);
    onComplete(GemErrorExtension.fromCode(err), hint);
  });

  final OperationResult resultString = staticMethod(
    'ActivationService',
    'generateLicenseKey',
    args: <String, dynamic>{
      'applicationId': applicationId,
      'productId': productId,
      'listener': progListener.id,
    },
  );

  final GemError errorCode = GemErrorExtension.fromCode(
    resultString['result'],
  );

  if (errorCode != GemError.success) {
    return null;
  }

  return TaskHandlerImpl(progListener.id);
}