Anyline Flutter Plugin

pub package

Anyline is a mobile OCR SDK, which can be configured by yourself to scan all kinds of numbers, characters, text and codes.

The plugin enables the connection to the SDK via Flutter.

Requirements:

iOSAndroid
baseSDK >= 10minSDK >= 19

Example

This is just a minimal example function to show how to use our plugin as quick as possible. For the code of our Flutter example app check out the anyline_demo module.

void scanWithAnyline() async {
  /// Instantiate the plugin.
  var anylinePlugin = AnylinePlugin();

  /// Load the config file which also includes the license key (for more info
  /// visit documentation.anyline.com).
  var config = await rootBundle.loadString("config/AnalogMeterConfig.json");

  /// Start the scanning process.
  var stringResult = await anylinePlugin.startScanning(config);

  /// Convert the stringResult to a Map to access the result fields. It is
  /// recommended to create result classes that fit your use case. For more
  /// information on that, visit the Flutter Guide on documentation.anyline.com.
  Map<String, dynamic> result = jsonDecode(stringResult);
}

Quick Start Guide

For a more in-depth guide, consider checking out the Anyline Flutter Guide on documentation.anyline.com.

1. Get a License

Get your trial license to try Anyline inside your app. Reach out to our sales team to get a commercial license.

2. Get the Anyline flutter plugin

Add this to your package's pubspec.yaml file:

dependencies:
  anyline_plugin: ^24.1.0

Install it with Flutter:

  $ flutter pub get

3. Import the plugin into your Dart file

import 'package:anyline_plugin/anyline_plugin.dart';

4. Add the config file to the assets in your pubspec.yaml

flutter:
  assets:
    - path-to-your-json-config

Add a JSON file with the proper structure and elements. The JSON config contains:

  1. The license key
  2. Options field with
  • AnylineSDK config parameter
  • “segment”: which contains the scanModes for the UI Segment (e.g. switch between Analog and Digital) - optional
  1. OCR field with (Only if you want to use the OCR module)
  • your custom training data
  • RegEx validation

If you want to get detailed information about the config JSON, check out the official documentation.

6. Call the Anyline component

Instantiate the Plugin

var anylinePlugin = AnylinePlugin();

Load config from file

var config = await rootBundle.loadString("your/Config/Path.json");

Start scanning and parse result

var resultString = await anylinePlugin.startScanning(config);

Currently the plugin does not provide seperate result classes, but this may be added in the future. For now feel free to create your own result class which fits your use case best. Alternatively, Flutter/Dart also supports serializing JSON using code generation libraries. To serialize the JSON string manually and convert it to a Map use jsonDecode() from dart:convert:

Map<String, dynamic> resultMap = jsonDecode(resultString);

From here you can access e.g. the image path of the cutout image at resultMap['imagePath'].

For detailed information on handling results and the result structure, check out our Anyline Flutter Guide on documentation.anyline.com.

7. Add TrainData to the OCR Module (optional)

If you are using the ANYLINE_OCR module, you'll have to add some traineddata. There are some predefined traineddata which you can find in the example app. Also the OCR Config has to reflect the path. Check the VoucherConfig.json in the example/config folder.

IMPORTANT: The trainedFiles have to be directly in the Asset folder in Android.

iOS

ios   
 └─── myTrainedData.traineddata

Android

android   
   └─── app
         └─── src
               └─── main
                      └─── assets
                             └─── myTrainedData.traineddata || myTrainedData.any

Additional Functions

getLicenseExpiryDate

Get the expiration date of the provided license. Returns a string.

Images

Keep in mind, all the images are saved in the cache directory of the app. For performance reasons, we only provide the path as string, so we don't have to transfer the whole image through the bridge. Please be aware, that you should not use the images in the cache directory for persistent storage, but store the images in a location of your choice for persistence.

License

See LICENSE file.

Libraries

anyline_plugin
constants
exceptions