generateLicenseKey static method
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:- GemError.success: Generation succeeded. The
hintmay contain the license key. - GemError.required: Activation service was unreachable or no internet.
- GemError.invalidInput: Invalid input; check the
hintfor details. - GemError.noMemory: Allocation failed on the platform.
- GemError.networkFailed: Network request failed to start.
- GemError.success: Generation succeeded. The
Returns
- TaskHandler: A task handle to observe or cancel the operation when the
request started successfully, otherwise
nullif 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);
}