Infinity Plugin API Reference
This page documents all methods and event streams available in the Anyline Infinity Plugin.
Overview
-
Flutter
| Method | Description | Returns |
|---|---|---|
|
Initializes the Anyline SDK with a license key |
|
|
Starts a scan session with a |
|
|
Stops the active scan session |
|
|
Switches scan mode using a full scan-start request |
|
|
Switches scan mode using a raw |
|
|
Submits a User Corrected Result report |
|
|
Exports cached scan events as a ZIP archive |
|
|
Returns the plugin version string |
|
|
Returns the native SDK version string |
|
|
Releases stream resources |
|
| Event Stream | Description | Type |
|---|---|---|
|
Emits scan results during an active session (0..N) |
|
|
Emits when a UI feedback element is tapped (0..N) |
|
Methods
All request and response types use the WrapperSession prefix (e.g. WrapperSessionScanStartRequest, WrapperSessionScanResponse). These are generated from the Anyline JSON schemas and represent the structured data exchanged between your application and the native SDK.
requestSdkInitialization
Initializes the Anyline SDK. Call this before starting any scan session.
Parameters:
-
request: aWrapperSessionSdkInitializationRequestcontaining your license key and optional configuration
Returns: WrapperSessionSdkInitializationResponse. See the overview table for platform-specific return type details.
-
Flutter
final request = WrapperSessionSdkInitializationRequest(
licenseKey: 'YOUR_LICENSE_KEY', // Replace with your Anyline License Key
// Optional: only needed if your app bundles custom ML model files provided by Anyline.
// The value depends on where these files are placed in your project. See the Developer Examples.
assetPathPrefix: 'flutter_assets/anyline_assets',
);
try {
final response = await infinityPlugin.requestSdkInitialization(request);
if (response.initialized == true) {
print('SDK initialized: ${response.succeedInfo?.toJson()}');
} else {
print('SDK init failed: ${response.failInfo?.lastError}');
}
} on PlatformException catch (e) {
print('SDK initialization error: ${e.message}');
}
requestScanStart
Starts a scan session. The method resolves/completes when the session ends (user dismissal, error, or programmatic stop). Intermediate scan results arrive via the onScanResults event stream.
Parameters:
-
request: aWrapperSessionScanStartRequestcontaining thescanViewConfigContentString(JSON)
Returns: WrapperSessionScanResponse when the session ends. See the overview table for platform-specific return type details.
-
Flutter
// Subscribe to scan results before starting the scan
final subscription = infinityPlugin.onScanResults.listen((result) {
final scanResult = result.exportedScanResults?.first;
print('Scan result: ${scanResult?.pluginResult?.toJson()}');
});
// Specify image format and delivery method for scan results
final scanResultConfig = WrapperSessionScanResultConfig(
imageContainer: ExportedScanResultImageContainer(
encoded: ExportedScanResultImageContainerEncoded(),
),
imageParameters: ExportedScanResultImageParameters(
format: ExportedScanResultImageFormat.PNG,
quality: 50,
),
);
// scanViewConfigJson is a JSON string containing your ScanViewConfig
final request = WrapperSessionScanStartRequest(
scanViewConfigContentString: scanViewConfigJson,
scanResultConfig: scanResultConfig,
);
// requestScanStart completes when the scan session ends
try {
final response = await infinityPlugin.requestScanStart(request);
print('Scan session ended: ${response.status}');
} on PlatformException catch (e) {
print('Scan start error: ${e.message}');
}
requestScanStop
Stops the active scan session.
Parameters:
-
request(optional): aWrapperSessionScanStopRequestwith stop configuration
Returns: No return value. See the overview table for platform-specific details.
-
Flutter
// Stop with default behavior
await infinityPlugin.requestScanStop();
// Or stop with an optional reason (surfaces in abortInfo.message on the scan response)
final stopRequest = WrapperSessionScanStopRequest(
message: 'Scan stopped: no result within timeout',
);
await infinityPlugin.requestScanStop(stopRequest);
requestScanSwitchWithScanStartRequestParams
Switches to a new scan mode without stopping the current session. Uses a full WrapperSessionScanStartRequest allowing you to change all scan parameters.
Parameters:
-
request: aWrapperSessionScanStartRequestwith the new configuration
Returns: No return value. See the overview table for platform-specific details.
Code examples for both switch methods are shown below.
requestScanSwitchWithScanViewConfigContentString
Switches to a new scan mode using only a raw ScanViewConfig JSON string. Use this when you only need to change the scan configuration without modifying other request parameters.
Parameters:
-
scanViewConfigContentString: a raw JSON string containing the newScanViewConfig
Returns: No return value. See the overview table for platform-specific details.
-
Flutter
Switch to a new scan mode using a full scan-start request. For example, to change the scan configuration, save result images to a directory, and set a workflow correlationId:
import 'package:path_provider/path_provider.dart';
final appDir = await getApplicationDocumentsDirectory();
final resultPath = '${appDir.path}/results/';
// newScanViewConfigJson: a JSON string containing the replacement ScanViewConfig
final switchRequest = WrapperSessionScanStartRequest(
scanViewConfigContentString: newScanViewConfigJson,
scanResultConfig: WrapperSessionScanResultConfig(
cleanStrategy: WrapperSessionScanResultCleanStrategyConfig
.CLEAN_FOLDER_ON_START_SCANNING,
imageContainer: ExportedScanResultImageContainer(
saved: ExportedScanResultImageContainerSaved(
path: resultPath,
),
),
imageParameters: ExportedScanResultImageParameters(
quality: 50,
format: ExportedScanResultImageFormat.PNG,
),
),
scanViewInitializationParameters: ScanViewInitializationParameters(
correlationId: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
),
);
await infinityPlugin.requestScanSwitchWithScanStartRequestParams(switchRequest);
Or switch using only a raw ScanViewConfig JSON string:
await infinityPlugin.requestScanSwitchWithScanViewConfigContentString(
newScanViewConfigJson,
);
requestUCRReport
Submits a User Corrected Result (UCR) report. UCR allows you to send corrections for scan results back to Anyline for model improvement.
Parameters:
-
request: aWrapperSessionUcrReportRequestcontaining the corrected result data
Returns: WrapperSessionUcrReportResponse. See the overview table for platform-specific return type details.
-
Flutter
// pluginResult: obtained from the onScanResults event stream (see Scan Result Handling)
// userCorrectedValue: the value corrected by the user after reviewing the scan result
final ucrRequest = WrapperSessionUcrReportRequest(
blobKey: pluginResult.blobKey,
correctedResult: userCorrectedValue,
);
try {
final ucrResponse = await infinityPlugin.requestUCRReport(ucrRequest);
if (ucrResponse.status == WrapperSessionUcrReportResponseStatus.UCR_REPORT_SUCCEEDED) {
print('UCR submitted: ${ucrResponse.succeedInfo?.message}');
} else {
print('UCR failed: ${ucrResponse.failInfo?.lastError}');
}
} on PlatformException catch (e) {
print('UCR report error: ${e.message}');
}
requestExportCachedEvents
Exports all cached scan events as a ZIP archive. Useful for debugging or offline analytics.
Parameters: none
Returns: WrapperSessionExportCachedEventsResponse. See the overview table for platform-specific return type details.
-
Flutter
try {
final exportResponse = await infinityPlugin.requestExportCachedEvents();
if (exportResponse.status == WrapperSessionExportCachedEventsResponseStatus.EXPORT_SUCCEEDED) {
final filePath = exportResponse.succeedInfo?.exportedFile;
print('Events exported to: $filePath');
} else {
print('Export failed: ${exportResponse.failInfo?.lastError}');
}
} on PlatformException catch (e) {
print('Event export error: ${e.message}');
}
getPluginVersion
Returns the version string of the wrapper plugin itself.
Parameters: none
Returns: Version string. See the overview table for platform-specific return type details.
getSDKVersion
Returns the version string of the underlying native Anyline SDK.
Parameters: none
Returns: Version string. See the overview table for platform-specific return type details.
-
Flutter
// Get the plugin version (from pubspec.yaml)
final pluginVersion = await infinityPlugin.getPluginVersion();
// Get the native SDK version
final sdkVersion = await infinityPlugin.getSDKVersion();
Event Streams
onScanResults
Emits WrapperSessionScanResultsResponse objects during an active scan session. You may receive zero or more results before the session ends.
Subscribe to this event stream before calling requestScanStart.
See Scan Result Handling for details on the result structure.
-
Flutter
final subscription = infinityPlugin.onScanResults.listen((result) {
// Iterate over all results in this batch (may contain multiple when using composite scanning)
for (final scanResult in result.exportedScanResults ?? []) {
final pluginResult = scanResult.pluginResult;
print('Plugin result: ${pluginResult?.toJson()}');
// Handle images based on delivery method
final imageContainer = scanResult.imageContainer;
if (imageContainer?.saved != null) {
final saved = imageContainer!.saved!;
final basePath = saved.path ?? '';
final fullFramePath = '$basePath/${saved.images?.image}';
final cutoutPath = '$basePath/${saved.images?.cutoutImage}';
} else if (imageContainer?.encoded != null) {
final encoded = imageContainer!.encoded!;
// Decode from Base64 for display or upload
final fullFrameBase64 = encoded.images?.image;
final cutoutBase64 = encoded.images?.cutoutImage;
}
}
});
// Cancel when no longer needed
subscription.cancel();
onUIElementClicked
Emits UiFeedbackElementConfig objects when the user taps a UI feedback element during scanning. This is useful for interactive scan overlays.
See UI Feedback Config for details on configuring UI feedback elements.
-
Flutter
infinityPlugin.onUIElementClicked.listen((UiFeedbackElementConfig element) {
print('UI element tapped: ${element.id}');
});