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
Download the Flutter SDK and decompress the file.
Copy the entire Flutter SDK folder to your project.

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
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')
}
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
In your project, go to iOS > Runner.xcworkspace to open the Runner project in Xcode.
Add camera permissions to the Info.plist file of the Runner project. Customize the Value as needed.

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.

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

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:
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.comIndonesia site:
https://cloudauth-device.ap-southeast-5.aliyuncs.comUS West (Silicon Valley):
https://cloudauth-device.us-west-1.aliyuncs.comGermany (Frankfurt):
https://cloudauth-device.eu-central-1.aliyuncs.comChina (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:
| "1" |
DataSwitch | The timing for reporting device information.
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:
Return value: The return value is a string in the format
code,reason. In this format,codeis the error code andreasonis a description of the error. The code and reason are separated by a comma (,).The meaning of
codeandreasonmay differ between the iOS and Android platforms. For more information, see the documentation for each platform.
Call the setCustomUI() operation to customize UI colors:
Parameter:
params. This parameter accepts data in JSON format. For information about UI customization configurations, see the documentation for the native SDKs:
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.
This demo code is for integration reference only. Ensure that you use the latest SDK version in your project.