Integrating Cloud Functions in a Flutter application

Search This thread


Inactive Recognized Developer
Oct 12, 2009
Huawei P40
Cloud Functions enables serverless computing through Function as a Service (FaaS) capabilities to simplify app development and O&M. This helps you implement functions more simply and build service capabilities more quickly. The following describes how to integrate Huawei’s AppGallery Connect Cloud Function service in Flutter.
We will create a basic new project as an example but of course, you could make use of a project you already have that's using flutter!

Project Setup​

Install the Flutter environment.​

Download the Flutter SDK package and decompress the package to any directory.


Download the Flutter and Dart plugins in Android Studio.


Enable Huawei Cloud Functions​

Create an Android app in AppGallery Connect and enable Cloud Functions for it as detailed in this guide.
Now we can go ahead and create a cloud function as you require it to use this guide to help understand what can be done.
Once you are happy with your function (in this instance it might just be as simple as returning a hello world statement for testing) you can go ahead and create a HTTP trigger that will trigger the function.

Create Flutter Project​

Next create your flutter project in android studio (or open your existing project if you already have one!).


Download your agconnect-services.json file from the AppGallery Connect console and add it to your project under the ‘app’ directory


Within the project-level build.gradle file make sure to include the Huawei maven repo and add the agcp package as a dependency.

buildscript {
    repositories {
        maven { url '' }
    dependencies {
        classpath ''
        classpath 'com.huawei.agconnect:agcp:'

Next in your app level build.gradle apply the agconnect plugin as so:

apply plugin: ''
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.huawei.agconnect'

Then in your pubspec.yaml file add the Cloud Function SDK dependency.

    sdk: flutter
  agconnect_cloudfunctions: 1.2.0+300

Call the Cloud function​

The below code is an example of how you can call a simple cloud function and get the result returned.

FunctionCallable functionCallable = FunctionCallable("test-\$latest");
Map<String, dynamic> parameters = <String, dynamic>{
  'year': _functionTextController.text
FunctionResult functionResult = await;

Where test-\$latest is the HTTP trigger identifier.