All Products
Search
Document Center

ID Verification:Flutter integration

Last Updated:Nov 18, 2025

ID Verification provides a Flutter plugin that you can use to add electronic Know Your Customer (eKYC) remote identity verification to your Flutter application. This topic describes the integration process and provides sample code.

Limits

  • The software development kit (SDK) does not support emulators. You must use a physical device to develop and debug.

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

Configure dependencies

  1. Download the Flutter SDK and decompress the file.

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

    image.png

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

    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 the flatDir configuration to the allprojects field.

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

image.png

Configure Proguard obfuscation rules

If you have configured Proguard for code obfuscation in the release scenario, add the following rules to the android > app > proguard-rules.pro file in your project:

-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. In your project, 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

Select Runner and click the Build Phases tab. In the Copy Bundle Resources section, add the following four bundles.

The bundle files are located in the aliyun_face_plugin/ios/Products path of the SDK folder, within their respective framework directories.

  • 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

Select Pods and click the Build Settings tab. Under Linking, add the -ObjC flag to Other Linker Flags.

image.png

API reference

The Flutter SDK includes four API operations: initializing the SDK (initWithOptions), getting MetaInfos (getMetaInfos), starting verification (verify), and customizing the UI (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

The initWithOptions(options) operation initializes the SDK. Call this operation during a cold start of the application, as soon as possible after the user accepts the privacy policy.

options: Specifies optional parameters for information collection. This parameter is optional. The optional parameters are as follows:

Note
  • The ID Verification client has a built-in Device Guard security module. To meet data collection compliance requirements in different regions, it provides different data reporting sites. You can set CustomUrl and CustomHost to specify a reporting site based on user attributes.

    Note: You can specify only one reporting site within a single application session lifecycle. The server query region must match the reporting site.

  • Specify a reporting site:

    • Singapore site (default): https://cloudauth-device.ap-southeast-1.aliyuncs.com

    • Indonesia site: https://cloudauth-device.ap-southeast-5.aliyuncs.com

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

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

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

  • For more information about the regions supported by product servers, see Supported regions.

Field name

Description

Example

IPv6

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

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

  • 1: Yes (use an IPv6 domain name)

"1"

DataSwitch

The timing for reporting device information.

  • 0 (default): At initialization

  • 1: When getting the token

Note

We recommend using the default configurations.

"1"

CustomUrl

Sets the data reporting server domain name.

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

CustomHost

Sets the data reporting server host.

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

Get MetaInfos

The getMetaInfos() operation returns the environment context of the client. The client sends the MetaInfos to your business server. Your server then uses the MetaInfos to send an initialization request to Alibaba Cloud. This process is used to obtain the transactionId, which is required for the verification.

Start verification

Call the verify() operation to start a verification request.

  • Parameters of the verify() operation:

    • Required parameter: transactionId

    • Optional parameters:

      For information about how to configure the optional parameters (extParams), see the documentation for the native Android and iOS SDKs.

      Android

      Key

      Description

      Example (String)

      IdentityParams.OcrResultButtonColor

      The color of the button at the bottom of the OCR result page.

      #FF0000

      IdentityParams.RoundProgressColor

      The color of the circle during the face scan.

      #FF0000

      IdentityParams.ShowAlbumIcon

      In the certificate OCR step, specifies whether to show the album upload entry.

      • 1 (default): Show

      • 0: Do not show

      1

      IdentityParams.ShowOcrResult

      In the certificate OCR step, specifies whether to show the result page.

      • 1 (default): Show

      • 0: Do not show

      1

      IdentityParams.EditOcrResult

      In the certificate OCR step, specifies whether the result page is editable.

      • 1 (default): Editable

      • 0: Not editable

      1

      IdentityParams.MaxErrorTimes

      The maximum number of retries.

      The range is 3 to 10. The default is 10.

      10

      IdentityParams.CardOcrTimeOutPeriod

      The timeout period for the OCR step.

      The range is 20 to 60 seconds. The default is 20 seconds.

      20

      IdentityParams.FaceVerifyTimeOutPeriod

      The timeout period for the liveness collection and detection step.

      The range is 20 to 60 seconds. The default is 20 seconds.

      20

      IdentityParams.OcrResultTimeOutPeriod

      The duration for which the OCR result page is editable.

      You can customize this value. By default, there is no limit.

      60

      IdentityParams.SdkLanguage

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

      Note

      For a list of languages supported by the SDK, see Custom languages for Android and iOS SDKs.

      zh-Hans

      IdentityParams.CloseButtonLayout

      The layout of the Close button.

      • left (default): Left side

      • right: Right side

      left

      IdentityParams.WaterMark

      The watermark text after a successful OCR scan.

      Test watermark text

      IdentityParams.Protocol

      SDK Protocol.

      Note

      Get the `protocol` from the server-side Initialize API and pass it in the extension parameters. This can reduce internal API interactions in the SDK and improve the network experience.

      None

      iOS

      Key

      Description

      Example (String)

      kIdentityParamKeyNextButtonColor

      The color of the button at the bottom of the Optical Character Recognition (OCR) result page.

      #FF0000

      kIdentityParamKeyRoundProgressColor

      The color of the circle during the face scan.

      #FF0000

      kIdentityParamKeyOcrSelectPhoto

      Specifies whether to show the album upload entry during the certificate OCR step:

      • 1: Show (default)

      • 0: Hide

      1

      kIdentityParamKeyShowOcrResult

      Specifies whether to show the result page during the certificate OCR step:

      • 1: Show (default)

      • 0: Hide

      1

      kIdentutyParamKeyEditOcrResult

      Specifies whether the result page is editable during the certificate OCR step:

      • 0: Not editable

      • 1 (default): Editable

      1

      kIdentityParamKeyMaxRetryCount

      The maximum number of retries. You can set this to a value from 3 to 10. The default value is 10.

      10

      kIdentityParamKeyCardOcrTimeOutPeriod

      The timeout period for the OCR step. You can set this to a value from 20 to 60 seconds. The default value is 20 seconds.

      20

      kIdentityParamKeyFaceVerifyTimeOutPeriod

      The timeout period for the liveness collection and detection step. You can set this to a value from 20 to 60 seconds. The default value is 20 seconds.

      20

      kIdentityParamKeyCardOcrEditTimeOutPeriod

      The duration for which the OCR result page is editable. You can set this to a value from 60 to 180 seconds. By default, there is no limit.

      180

      kIdentityParamKeyLanguage

      Custom language settings for the SDK. By default, the SDK uses the language of the mobile device's operating system.

      Note

      For a list of languages supported by the SDK, see Custom languages for Android and iOS SDKs.

      zh-Hans

      kIdentityParamKeyDefaultLanguage

      The default language of the SDK. For valid values, see the kIdentityParamKeyLanguage field.

      The default value is en, which indicates English.

      en

      kIdentityParamKeyCloseButtonPosition

      The position of the SDK's Close button:

      • left: Left (default)

      • right: Right

      left

      kIdentityParamKeyWatermark

      The watermark text after successful OCR.

      Test watermark text

      kIdentutyParamKeyProtocol

      The SDK protocol.

      Note

      Obtain the protocol from the server-side Initialize API and pass it in the extension parameters. This can reduce internal SDK API interactions and improve the network experience.

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

  • Return value: The return value is a string in the format code,reason. In this format, code is the error code and reason is a description of the error. The code and reason are separated by a comma (,).

    The meaning of code and reason may differ between the iOS and Android platforms. For more information, see the documentation for each platform.

Call the setCustomUI() operation to customize UI colors:

Note

Each transactionId can be used only once. Otherwise, an error is returned. The error messages are as follows:

  • 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")),
          ])),
      ),
    );
  }
}

Download the Flutter Demo to view the complete code.

Important

This demo code is for integration reference only. Ensure that you use the latest SDK version in your project.