Intermediate: How to Integrate Bank Card Recognition Using Huawei ML Kit (Flutter)

In this article, we will learn how to implement Bank Card Recognition while doing payment. This service can quickly recognize information such as the bank card number, expiry date and organization name. It is widely used in finance and payment applications to quickly extract the bank card details.


1. Any operating system(i.e. MacOS, Linux, Windows)

2. Any IDE with Flutter SDK installed (i.e. IntelliJ, Android Studio and VsCode etc.)

3. A little knowledge of Dart and Flutter.

4. A Brain to think

Do you want to integrate Ml kit into your sample, refer below steps

1. We need to register as a developer account in AppGallery Connect.

2. Create an app by referring to Creating a Project and Creating an App in the Project

3. Set the data storage location based on current location.

4. Enabling Required API Services: ML Kit.

5. Generating a Signing Certificate Fingerprint.

6. Configuring the Signing Certificate Fingerprint.

7. Get your agconnect-services.json file to the app root directory.

Important: While adding app, the package name you enter should be the same as your Flutter project’s package name.

Note: Before you download agconnect-services.json file, make sure the required kits are enabled.

How to use Huawei Bank card recognition service

Bank card recognition service can input bank card information through video streaming, obtain the important text information such as the card number and expiration date of the bank card in the image.

Bank card identification provides processing plug-ins. Developers can integrate a bank card recognition plug-in without the need to process camera video stream data, thereby achieving rapid integration of bank card recognition capabilities.

This service recognizes bank cards in camera streams within angle offset of 15 degrees and extracts key information such as card number and expiration date. This service works with the ID card recognition service to offer a host of popular functions such as identity verification and bank card number input, making user operations easier than ever.

Let’s start development

Create Application in Android Studio.

1. Create Flutter project.

2. App level gradle dependencies. Choose inside project Android > app > build.gradle.

apply plugin: ‘’
apply plugin: ‘com.huawei.agconnect’

Root level gradle dependencies

maven {url ‘'}
classpath ‘com.huawei.agconnect:agcp:’

You need to add the permissions below in AndroidManifest file.

<manifest xlmns:android…>

<uses-permission android:name=”android.permission.CAMERA” />
<uses-permission android:name=”android.permission.READ_EXTERNAL_STORAGE” />
<uses-feature android:name=”” />
<uses-feature android:name=”” />
<application …

3. Refer below URL for cross-platform plugins. Download required plugins.

4. After completing all the above steps, you need to add the required kits’ Flutter plugins as dependencies to pubspec.yaml file. You can find all the plugins in with the latest versions.

sdk: flutter
shared_preferences: ^0.5.12+4
bottom_navy_bar: ^5.6.0
cupertino_icons: ^1.0.0
provider: ^4.3.3
http: ^0.12.2
path: ../huawei_ml/
uses-material-design: true
— assets/images/

5. After adding them, run flutter pub get command. Now all the plugins are ready to use.

6. Open main.dart file to create UI and business logics.

Note: Set multiDexEnabled to true in the android/app directory so the app will not crash.

Check Camera permission before start scan.

permissionRequest() async {
bool permissionResult =
await HmsScanPermissions.hasCameraAndStoragePermission();
if (permissionResult == false) {
await HmsScanPermissions.requestCameraAndStoragePermissions();

To access the bank card recognition plugin APIs, first create an MLBankcardAnalyzer object.

Next create an MLBankcardSettings object to configure the recognition.

In order to recognize the bank card, we’ll call the captureBankcard method via the MLBankcardAnalyzer class.

In turn, this method gives us bank card information via MLBankcard class.

The result of originalBitmap and numberBitmap comes as URI. So convert Uri to File with AbsolutePath.

Final Code Here


Tips & Tricks

1. Download latest HMS Flutter plugin.

2. Set minSDK version to 19 or later.

3. Do not forget to click pug get after adding dependencies.

4. Latest HMS Core APK is required.


In this article, we have learned to develop simple hotel booking application, we can avoid manual filling card details into payment page, using ML Kit we can quickly recognized the card details.

Thanks for reading! If you enjoyed this story, please click the Like button and Follow. Feel free to leave a Comment 💬 below.