DEV Community

Zachary Powell
Zachary Powell

Posted on

Integrating Cloud Functions in a Flutter application

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 thats using flutter!

Project Setup

Install the Flutter environment.

Download the Flutter SDK package and decompress the package to any directory.
Image description
Download the Flutter and Dart plugins in Android Studio.
Image description

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 use this guide to help understand what can be done.
Once your 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!).
Image description
Download your agconnect-services.json file from the AppGallery Connect console and add it into your project under the 'app' directory
Image description

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

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

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

Call the Cloud function

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

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

Top comments (0)