All Products
Search
Document Center

ID Verification:Flutter integration

Last Updated:Jul 09, 2026

ID Verification provides a Flutter plugin that lets you add eKYC remote identity verification to your Flutter app. This topic walks through the integration process with sample code.

Limits

  • The SDK does not support emulators. Use a physical device for development and debugging.

  • System requirements: iOS 9.0 or later and Android 5.0 or later.

Configure dependencies

  1. Go to Client SDK release notes to download and extract the Flutter SDK.

  2. Copy the entire Flutter SDK folder to your project.

    image.png

  3. In your project's pubspec.yaml, add the Alibaba Cloud plugin dependency under dev_dependencies.

    aliyun_face_plugin:
        path: aliyun_face_plugin

    image.png

Configure the Android environment

Add module dependencies

In your project's android > build.gradle file, add flatDir to the allprojects field.

flatDir {
    dirs project(':aliyun_face_plugin').file('libs')
}

image.png

Configure Proguard obfuscation rules

If you use Proguard for code obfuscation in release builds, add the following rules to android > app > proguard-rules.pro:

-verbose
-keep class com.idv.identity.platform.api.** {*;}
-keep class com.idv.identity.platform.log.** {*;}
-keep class com.idv.identity.util.IdentityUtils {*;}
-keep class com.idv.identity.ocr.IdentityOcrApi {*;}
-keep class com.idv.identity.platform.model.** {*;}
-keep class com.idv.identity.platform.config.** {*;}
-keep class com.idv.identity.face.IdentityFaceApi {*;}


-keep class com.face.verify.intl.** {*;}
-keep class com.alibaba.fastjson.** {*;}
-keep class face.security.device.api.** {*;}
-keep class net.security.device.api.** {*;}
-keep class com.dtf.toyger.** { *; }
-dontwarn net.security.device.api.**
-dontwarn face.security.device.api.**


-keep class com.idv.identity.service.algorithm.** {*;}
-keep class com.idv.identity.base.algorithm.** {*;}
-keep class com.idv.identity.quality.QualityRouter {*;}
-keep class com.idv.identity.blink.BlinkRouter {*;}
-keep class com.idv.identity.service.IdentityFaceService {*;}
-keep class com.idv.identity.service.ocr.IdentityDocService {*;}

-keep class com.alibaba.sdk.android.oss.** { *; }
-dontwarn okio.**
-dontwarn org.apache.commons.codec.binary.**



# NFC
-keep class com.idv.identity.nfc.IdentityNfcApi { *; }
-keep class org.jmrtd.** {*;}
-keep class net.sf.**{*;}
-keep class org.**{*;}
-keep class cn.**{*;}


# Please add these rules to your existing keep rules to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.fasterxml.**
-dontwarn com.google.**
-dontwarn java.applet.Applet
-dontwarn java.awt.**
-dontwarn javax.**
-dontwarn org.**
-dontwarn retrofit2.**
-dontwarn springfox.documentation.spring.web.json.Json

# Optional: Log obfuscation
-assumenosideeffects class android.util.Log {
    public static *** d(...);
}

Configure the iOS environment

Add camera permissions

  1. Go to iOS > Runner.xcworkspace to open the Runner project in Xcode.

  2. Add camera permissions to the Info.plist file of the Runner project. Customize the Value as needed.

    image.png

Add bundles

Go to Runner > Build Phases > Copy Bundle Resources and add the following four bundles.

These bundles are located in the aliyun_face_plugin/ios/Products directory, each inside its corresponding framework folder.

  • ToygerService.bundle: Located in ToygerService.framework.

  • AliyunIdentityPlatform.bundle: Located in AliyunIdentityPlatform.framework.

  • AliyunIdentityOCR.bundle: Located in AliyunIdentityOCR.framework.

  • AliyunIdentityFace.bundle: Located in AliyunIdentityFace.framework.

image.png

Add the -ObjC linker flag

Go to Pods and click Build Settings. Under Linking, add -ObjC to Other Linker Flags.

image.png

API reference

The Flutter SDK provides four operations: initWithOptions, getMetaInfos, verify, and setCustomUI.

class AliyunFacePlugin {
  // Initializes the SDK.
  Future<void> init() {
    return AliyunFacePluginPlatform.instance.init();
  }
  // Initializes the SDK with options.
  Future<void> initWithOptions(Map<String, String> options) {
    return AliyunFacePluginPlatform.instance.initWithOptions(options);
  }

  // Gets the metainfos of the client. The metainfos are used to obtain the transaction ID from the server.
  Future<String?> getMetaInfos() {
    return AliyunFacePluginPlatform.instance.getMetaInfos();
  }
  
  // Starts the verification process.
    Future<String?> verify(Map<String, String> params) {
    return AliyunFacePluginPlatform.instance.verify(params);
  }
  
  // Customizes the UI.
  Future<String?> setCustomUI(String configuration) {
    return AliyunFacePluginPlatform.instance.setCustomUI(configuration);
  }
}

Initialize the SDK

Call initWithOptions(options) during app cold start, as early as possible after the user accepts the privacy policy.

The options parameter, which is null by default, specifies optional data collection settings.

Important
  • The ID Verification client includes a built-in security module known as the device helper. The device helper provides various data reporting regions to meet local data collection compliance requirements. You can set CustomUrl and CustomHost to specify different reporting sites based on user attributes.

  • Only one data reporting region can be specified per application session lifecycle. The region for server-side queries must match the reporting region. The supported regions vary by product. For more information, see Supported regions.

  • For each region, the CustomUrl is as follows:

    • China (Hong Kong): https://cloudauth-device.cn-hongkong.aliyuncs.com

    • Singapore: https://cloudauth-device.ap-southeast-1.aliyuncs.com

    • Indonesia (Jakarta): https://cloudauth-device.ap-southeast-5.aliyuncs.com

    • US (Silicon Valley): https://cloudauth-device.us-west-1.aliyuncs.com

    • Germany (Frankfurt): https://cloudauth-device.eu-central-1.aliyuncs.com

    • Malaysia (Kuala Lumpur): https://cloudauth-device.ap-southeast-3.aliyuncs.com

Parameter

Description

Example

IPv6

Indicates whether to use an IPv6 domain name to report device information:

  • 0 (default): No (uses an IPv4 domain name)

  • 1: Yes (uses an IPv6 domain name)

"1"

DataSwitch

Controls when to report device information:

  • 0 (default): When the SDK initializes

  • 1: When you obtain a token

Note

The default setting is recommended.

"1"

CustomUrl

Sets the server domain name for data reporting.

See CustomUrl for each region.

CustomHost

Sets the server host for data reporting.

"cloudauth-device.ap-southeast-1.aliyuncs.com"

Note

This example is for the Singapore region. For server hosts in other regions, see CustomUrl for each region.

Get MetaInfos

getMetaInfos() returns the client environment context. Pass this value to your server, which then uses it to request a transactionId from Alibaba Cloud.

Start verification

Call verify() to start a verification request.

  • Parameters of the verify() operation:

    • Required parameter: transactionId

    • Optional parameters:

      Optional parameters (extParams) — native Android and iOS SDK documentation

      Android

      Key

      Description

      Example (String type)

      IdentityParams.OcrResultButtonColor

      Button color on the OCR result page.

      #FF0000

      IdentityParams.RoundProgressColor

      Circle color during face scanning.

      #FF0000

      IdentityParams.ShowBlbumIcon

      Show album upload entry during OCR:

      • 1 (default): Show

      • 0: Do not show

      1

      IdentityParams.ShowOcrResult

      Show OCR recognition result page:

      • 1 (default): Show

      • 0: Do not show

      1

      IdentityParams.EditOcrResult

      OCR result page editable:

      • 1 (default): Editable

      • 0: Not editable

      1

      IdentityParams.MaxErrorTimes

      Maximum retries.

      Range: 3–10. Default: 10.

      10

      IdentityParams.CardOcrTimeOutPeriod

      OCR recognition timeout.

      Range: 20–60 seconds. Default: 20 seconds.

      20

      IdentityParams.FaceVerifyTimeOutPeriod

      Liveness detection timeout.

      Range: 20–60 seconds. Default: 20 seconds.

      20

      IdentityParams.OcrResultTimeOutPeriod

      OCR result page edit timeout, in seconds.

      Default: unlimited.

      60

      IdentityParams.SdkLanguage

      You can customize the display language for the SDK. By default, the SDK uses your mobile device's system language.

      Note

      For a list of supported languages, see Customize languages for the Android and iOS SDKs.

      zh-Hans

      IdentityParams.CloseButtonLayout

      Layout of the Close button:

      • left (default): Left side

      • right: Right side

      left

      IdentityParams.WaterMark

      Watermark text displayed after successful OCR.

      Test watermark text

      IdentityParams.Protocol

      Protocol string from the server-side Initialize API response.

      Note

      Pass the protocol value from the server-side Initialize API response to reduce internal API calls and improve performance.

      None

      iOS

      Key

      Description

      Example (string)

      kIdentityParamKeyNextButtonColor

      Color of the bottom button on the OCR recognition result page.

      #FF0000

      kIdentityParamKeyRoundProgressColor

      Color of the circular progress indicator during the face scan.

      #FF0000

      kIdentityParamKeyOcrSelectPhoto

      Whether to show the photo album upload option during ID OCR recognition:

      • 1 (default): Show

      • 0: Do not show

      1

      kIdentityParamKeyShowOcrResult

      Whether to show the recognition result page after ID OCR recognition:

      • 1 (default): Show

      • 0: Do not show

      1

      kIdentityParamKeyEditOcrResult

      Whether the recognition result page is editable during ID OCR recognition:

      • 1 (default): Editable

      • 0: Not editable

      1

      kIdentityParamKeyMaxRetryCount

      Maximum number of retries. Valid values: 3 to 10. Default value: 10.

      10

      kIdentityParamKeyCardOcrTimeOutPeriod

      Timeout for OCR recognition, in seconds. Valid values: 20 to 60. Default value: 20.

      20

      kIdentityParamKeyFaceVerifyTimeOutPeriod

      Timeout for liveness detection, in seconds. Valid values: 20 to 60. Default value: 20.

      20

      kIdentityParamKeyCardOcrEditTimeOutPeriod

      Duration (in seconds) that the OCR recognition result page remains editable. Valid values: 60 to 180. By default, the duration is unlimited.

      180

      kIdentityParamKeyLanguage

      SDK display language. By default, the SDK uses the system language.

      Note

      For a list of supported languages, see Customize languages for the Android and iOS SDKs.

      zh-Hans

      kIdentityParamKeyDefaultLanguage

      Default SDK language. For valid values, refer to kIdentityParamKeyLanguage.

      The default value is en (English).

      en

      kIdentityParamKeyCloseButtonPosition

      Position of the close button in the SDK UI:

      • left (default)

      • right

      left

      kIdentityParamKeyWatermark

      Watermark text displayed after successful OCR recognition.

      Test watermark text

      kIdentityParamKeyProtocol

      Pre-fetched SDK protocol content.

      Note

      Obtain the protocol from the server-side Initialize API and pass it here to reduce internal SDK API calls and improve startup performance.

      968412EB*******...

  • Return value: a comma-separated string in the format code,reason, where code is the error code and reason is the error description.

    The code and reason values differ between iOS and Android. For more information, see the platform-specific SDK documentation.

Call setCustomUI() to customize the UI colors:

Note

Each transactionId can be used only once. Reuse causes the following errors:

  • iOS: 2002: ZIM network failure.

  • Android: 1001, NET_RESPONSE_INVALID.

Sample code

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';

import 'package:flutter/services.dart';
import 'package:aliyun_face_plugin/aliyun_face_plugin.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _infos = 'Unknown';
  final _aliyunFacePlugin = AliyunFacePlugin();

  @override
  void initState() {
    super.initState();

    // Call the init operation early in the app startup process.
    Map<String, String> options = {"CustomUrl":"https://cloudauth-device.ap-southeast-5.aliyuncs.com",
                                   "CustomHost":"cloudauth-device.ap-southeast-5.aliyuncs.com"};
    _aliyunFacePlugin.initWithOptions(options);
  }

  Future<void> getMetaInfos() async {
    String metainfos;

    try {
      // Get the client metainfos. Send the information to the server to call the relevant server-side API operations and obtain the transaction ID.
      metainfos = await _aliyunFacePlugin.getMetaInfos() ?? 'Unknown metainfos';
    } on PlatformException {
      metainfos = 'Failed to get metainfos.';
    }

    setState(() {
      _infos = "metainfos: " + metainfos;
    });
  }

  Future<void> setCustomUi() async {
    try {
      String config = "{\"faceConfig\":{ \"faceBGColor\": \"#FF33FF\"}}";
      await _aliyunFacePlugin.setCustomUI(config) ?? '-1,error';
    } on PlatformException {
      '-2,exception';
    }
  }

  Future<void> startVerify() async {
    String verifyResult;
    try {
      String transactionId = "xxxx"; // The transaction ID.
      Map<String, String> params = {
        "transactionId": transactionId,
      };
      if (Platform.isIOS) {
        params.addAll({"kIdentityParamKeyLanguage": "en"});
      } else if (Platform.isAndroid) {
        params.addAll({"SdkLanguage": "en"});
      }

      verifyResult = await _aliyunFacePlugin.verify(params) ?? '-1,error';
    } on PlatformException {
      verifyResult = '-2,exception';
    }

    setState(() {
      _infos = "verifyResult: " + verifyResult;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Aliyun face plugin demo')),
        body: Center(
          child: Column(children: <Widget>[
            Text('$_infos\n'),
            ElevatedButton(
              onPressed: () async {
                getMetaInfos();
              },
              child: Text("getMetaInfos")),
            ElevatedButton(
              onPressed: () async {
                startVerify();
              },
              child: Text("startVerify")),
            ElevatedButton(
              onPressed: () async {
                setCustomUi();
              },
              child: Text("setCutomUi")),
          ])),
      ),
    );
  }
}

Go to Client SDK release notes to download the Flutter demo and view the complete code.

Important

This demo is for reference only. Use the latest SDK version in your project.