[Huawei Developers] John Wo:
Introduction

Huawei supports so many features with Machine learning Kit. It grows up day to day and comes with new MLkit features. In this article, I will show how to develop flutter application using the Huawei ML kit Text Translation. We can develop different types of AI apps using ML Kit.

Flutter ML Plugin enables communication between the HMS Core ML SDK and flutter platform. This plugin exposes all functionality provided by the ML SDK.

ML Kit Services

Huawei ML Kit provides wide range of machine learning services and we can integrate easily into our application.

Flutter setup

Refer this URL to setup Flutter.

Software Requirements

1. Android Studio 3.X

2. JDK 1.8 and later

3. SDK Platform 19 and later

4. Gradle 4.6 and later

Steps to integrate service

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 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

Development Process

1. Create Flutter project.

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

apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'

Root level gradle dependencies

maven {url 'https://developer.huawei.com/repo/'}
classpath 'com.huawei.agconnect:agcp:1.4.1.300'

Add the below permissions in Android Manifest file.

<manifest xlmns:android...>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<application>
</manifest>

3. Add HMS Ads kit plugin download using below URL.

https://developer.huawei.com/consum...Library-V1/flutter-plugin-0000001052836687-V1

4. On your Flutter project directory find and open your pubspec.yaml file and add library to dependencies to download the package from pub.dev. Or if you downloaded the package from the HUAWEI Developer website, specify the library path on your local device. For both ways, after running pub get command, the plugin will be ready to use.

name: mlsample
description: A new Flutter application.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
huawei_ml:
path: ../huawei_ml/
cupertino_icons: ^1.0.0
image_picker: ^0.6.7+4
path_provider: ^1.6.11

dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true

5. We can check the plugins under External Libraries directory.

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

Text Translation

The Translation service can translate text into different languages through the server on the cloud. currently this service supports Chinese, English, German, Spanish, French, and Russian (automatic model download is supported), and online translation of text in Simplified Chinese, English, French, Arabic, Thai, Spanish, Turkish, Portuguese, Japanese, German, Italian, Russian, Polish, Malay, Swedish, Finnish, Norwegian, Danish, and Korean.

Create an MlTranslatorSettings object and set the values.

MlTranslatorSettings _settings;
@override
void initState() {
_settings = new MlTranslatorSettings();
super.initState();
}

More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0203430600164170056