Getting Started with Infinity Plugins
This guide walks you through installing the Anyline Infinity Plugin, initializing the SDK, and running your first scan.
Prerequisites
-
A valid Anyline license key. Obtain one by following the License Key Generation guide.
Every license is bound to a Bundle Identifier. If you change your Bundle Identifier, you will require a new license. This also ensures that your license key cannot be used in any other application. -
Platform-specific requirements:
-
Flutter: Flutter 3.x+, Dart 3.x+
-
Step 1: Install the Plugin
-
Flutter
Add the Anyline plugin to your pubspec.yaml:
dependencies:
anyline_plugin: ^56.0.0
Then install the dependency:
flutter pub get
On Android, the plugin’s build.gradle automatically adds the Anyline Maven repository.
If your app uses FAIL_ON_PROJECT_REPOS in android/settings.gradle, add the repository manually:
dependencyResolutionManagement {
repositories {
maven { url 'https://mobile-sdk-android.anyline.io/release/' }
}
}
Step 2: Import the Plugin
-
Flutter
import 'package:anyline_plugin/anyline_infinity_plugin.dart';
final infinityPlugin = AnylineInfinityPlugin();
Step 3: Initialize the SDK
Initialize the Anyline SDK with your license key. This must be called before starting any scan.
-
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}');
}
Step 4: Prepare a ScanViewConfig
Create a ScanViewConfig JSON to define what and how to scan. See Constructing your Configuration JSON using JSON Schemas for details on building your configuration, and ScanViewConfig Documentation for the full schema reference.
{
"viewPluginConfig": {
"pluginConfig": {
"id": "barcode",
"barcodeConfig": {
"barcodeFormats": ["ALL"]
},
"cancelOnResult": true (1)
}
}
}
| 1 | cancelOnResult stops scanning after the first result. Set to false for continuous scanning. |
Save this JSON as a file in your app’s assets and load it as a string at runtime. The resulting string is the scanViewConfigJson used in Step 5.
|
Step 5: Start Scanning and Handle Results
Set up a result subscription, configure the scan request, and start the scan session. The scan session remains active until explicitly stopped or until the user dismisses the scan view. Results arrive as events during the session — you can receive zero or more results before the session ends.
-
Flutter
// 1. Subscribe to scan results before starting the scan
final subscription = infinityPlugin.onScanResults.listen((result) {
for (final scanResult in result.exportedScanResults ?? []) {
final pluginResult = scanResult.pluginResult;
print('Plugin result: ${pluginResult?.toJson()}');
}
});
// 2. Configure how scan results are delivered
final scanResultConfig = WrapperSessionScanResultConfig(
imageContainer: ExportedScanResultImageContainer(
encoded: ExportedScanResultImageContainerEncoded(),
),
imageParameters: ExportedScanResultImageParameters(
format: ExportedScanResultImageFormat.PNG,
quality: 50,
),
);
// 3. Build the scan request
// scanViewConfigJson is a JSON string containing your ScanViewConfig
final request = WrapperSessionScanStartRequest(
scanViewConfigContentString: scanViewConfigJson,
scanResultConfig: scanResultConfig,
);
// 4. Start scanning — 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}');
}
// 5. Cancel subscription when done
subscription.cancel();
Subscribe to onScanResults before calling requestScanStart. The result stream does not buffer events — any results arriving before the subscription is active are lost.
|
See Scan Result Handling for details on result structure and image handling.
Step 6: Stop Scanning
The scan session ends naturally after the first result when cancelOnResult is set to true in the ScanViewConfig, or after all sub-plugin results are collected when using composite scanning. You only need to call requestScanStop for continuous scanning (cancelOnResult: false) or when you want to stop the session before any result is received.
|
Stop the active scan session programmatically:
-
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);
Next Steps
-
Infinity Plugin API Reference (full method and event reference)
-
Scan Result Handling (working with scan results and images)
-
Advanced Topics (scan switching, UCR, and platform-specific tips)