Skip to main content

SDK Initialization | Flutter Document Scanner

The Scanbot SDK must be initialized before usage. Make sure to call the initialization after entering the main widget creation.

Free Developer Support

We provide free "no-strings-attached" developer support for the implementation & testing of the Scanbot SDK. If you encounter technical issues with integrating the Scanbot SDK or need advice on choosing the appropriate framework or features, please visit our Support Page.

To initialize the SDK, add the following code snippet:

import 'package:scanbot_sdk/scanbot_sdk.dart';

var config = ScanbotSdkConfig(
licenseKey: "<YOUR_SCANBOT_SDK_LICENSE_KEY>",
loggingEnabled: true,
imageFormat: ImageFormat.JPG,
imageQuality: 80,
storageBaseDirectory: "file:///some/optional/custom-storage-dir/",
documentDetectorMode: DocumentDetectorMode.ML_BASED,
licenseErrorHandler: (status, feature, message) {
print("status: $status, feature: $feature, message: $message");
},
);

ScanbotSdk.initScanbotSdk(config);

The following configuration options can be passed on initialization:

  • licenseKey: Your license key for the Scanbot SDK.
  • imageQuality: Optional image quality value. Defines the quality factor of JPEG images. The value must be between 1 and 100, where 100 means maximum quality and largest file size. The default value is 80, which is a good compromise between image file size and document legibility.
  • imageFormat: Optional image format in which all pages will be stored.
  • loggingEnabled: Optional logging flag. While it may be useful for development, consider switching logging OFF in production builds for security and performance reasons!
  • storageBaseDirectory: Optional parameter for overriding the default storage directory as a file URI of the Scanbot SDK.
  • documentDetectorMode - Optional mode for document detection.
    • 'ML_BASED' is the default mode, based on Machine Learning-based approach;
    • 'EDGE_BASED' legacy mode, based on classic Computer Vision algorithms.
  • encryptionParameters: Optional parameter for the Configuration class for AES encryption, enabling encryption inside SDK storage.
  • useCameraX: Optional flag to enable the usage of CameraX Android APIs for Ready to Use UI components (Android only). Default is true.
  • allowGpuAcceleration: Optional flag to enable GPU acceleration for TensorFlow ML models (Android only). Default is true. If set to false, GPU acceleration will be disabled for Barcode Scanner, Document Scanner, and Generic Document Recognizer.
  • allowXnnpackAcceleration: Optional flag that controls whether XNN pack optimizations should be used (Android only). Default is true.

Add Scanbot SDK license key

info

You can use the Scanbot SDK for quick testing or evaluation purposes even without a license key. However, the SDK will only work for 60 seconds per app session and may not be used for production purposes. Want to scan longer than 60 seconds? Get your free trial license key here.

Example code for initialization with license:

import 'package:scanbot_sdk/scanbot_sdk.dart';

class MyApp extends StatefulWidget {

_MyAppState createState() {
// Please note: this is just an example license key string (it is not a valid license)
String licenseKey =
"fXbN2PmyqEAZ+btdkSIS36TuX2j/EE5qxVNcZMXYErbLQ" +
"3OBnE10aOQxYI8L4UKwHiZ63jthvoFwUevttctBk0wVJ7Z" +
"+Psz3/Ry8w7pXvfpB1o+JrnzGGcfwBnRi/5raQ2THDeokR" +
"RB1keky2VBOFYbCfYt3Hqms5txF2z70PE/SBTMTIVuxL7q" +
"1xcHDHclbEBriDtrHw8Pmhh9FqTg/r/4kRN/oEX37QGp+Y" +
"3ogwIBbSmV+Cv+VuwtI31uXY3/GkyN/pSJZspIl+exwQDv" +
"O0O1/R/oAURpfM4ydaWReRJtjW8+b1r9rUgPERguaXfcse" +
"HlnclItgDfBHzUUFJJU/g==\nU2NhbmJvdFNESwppby5zY" +
"2FuYm90LmRlbW8ueGFtYXJpbgoxNDg0NjExMTk5CjcxNjc" +
"KMw==\n";
var config = ScanbotSdkConfig(
licenseKey: licenseKey,
loggingEnabled: true
);
ScanbotSdk.initScanbotSdk(config);
});
return _MyAppState();
}
}

You will be unable to use any of the SDK features if the license key is corrupted, expired, or invalid in any other way.

Please make sure that you have inserted the exact key as it was provided by us, including all encoded line breaks \n.

App Identifier

Every app has a unique identifier (sometimes also known as "bundle identifier" or "application ID"). Your license will be bound to this identifier. To request a trial license or purchase a production license you have to provide us the bundle identifier of your app.

For Android: Please see the applicationId in the app-level build.gradle file of your android project:

defaultConfig {
...
applicationId "io.scanbot.example.app.flutter"
}

For iOS: In Xcode see the Bundle Identifier in the "General" settings tab of your project.

Image Quality / Compression

The initializeSdk function can take some optional parameters that specify the image storage format and compression for generated Page images. Page images are all images created by the Ready-To-Use UI Components (like Document Scanner, Cropping UI, etc), as well as all image manipulation functions working with Page objects as input (like applyImageFilterOnPage, detectDocumentOnPage, etc).

import 'package:scanbot_sdk/scanbot_sdk.dart';

var config = ScanbotSdkConfig(
imageFormat: ImageFormat.JPG,
imageQuality: 80,
);

ScanbotSdk.initScanbotSdk(config);
  • imageQuality - defines the quality factor of JPEG images. The value must be between 1 and 100, where 100 means maximum quality and largest file size. The default value is 80 which is a good compromise between image file size and document legibility.
  • imageFormat - either JPG or PNG. The default value is JPG.

License handling

caution

If your Scanbot SDK license has expired, any call to the Scanbot SDK API will return empty results. To prevent this you should always check for license expiration during the runtime via ScanbotSdk.getLicenseStatus(). If the result of await returns result.isLicenseValid == false, you should disable any usage of the Scanbot SDK (functions, UI components, etc).

See license handling section to learn how to handle the different license statuses in your app.

Logging

When initializing the Scanbot SDK you can enable logging of the SDK. By default logging is disabled.

import 'package:scanbot_sdk/scanbot_sdk.dart';

var config = ScanbotSdkConfig(
loggingEnabled: true,
// ...
);
ScanbotSdk.initScanbotSdk(config);

On Android logs are printed into LogCat as well as saved on the device. The easiest way to check the log outputs on Android is to use Android Debug Bridge (adb). (e.g. $ adb -s <DEVICE_ID> shell "logcat")

On iOS all logs are printed to the console. Please use Xcode to check the log outputs. There will be no log files created by the Scanbot SDK plugin.

Please note: While it may be useful for development, consider switching logging OFF in production builds for security and performance reasons!

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get your free Trial License

What do you think of this documentation?