[Huawei Developers] Basavaraj.navi:
Introduction

Welcome Folks, in this article, I will explain what is Huawei Remote configuration? How does Huawei Remote Configuration work in Flutter? At the end of this tutorial, we will create the Huawei Remote Configuration Flutter taxi booking application.

In this example, I am enabling/Disabling share feature from remote configuration. When share feature is enabled user can book share cab otherwise user can’t see the share feature.

What is Huawei Remote Configuration?

Huawei Remote Configuration is cloud service. It changes the behavior and appearance of your app without publishing an app update on App Gallery for all active users. Basically, Remote Configuration allows you to maintain parameters on the cloud, based on these parameters we control the behavior and appearance of your app. In the festival scenario, we can define parameters with the text, color, images for a theme which can be fetched using Remote Configuration.

How does Huawei Remote Configuration work?

Huawei Remote Configuration is a cloud service that allows you change the behavior and appearance of your app without requiring users to download an app update. When using Remote Configuration, you can create in-app default values that control the behavior and appearance of your app. Then, you can later use the Huawei console or the Remote Configuration to override in-app default values for all app users or for segments of your user base. Your app controls when updates are applied, and it can frequently check for updates and apply them with a negligible impact on performance.

In Remote Configuration, we can create in-app default values that control the behavior and appearance (such as text, color, and image, etc.) in the app. Later on, with the help of Huawei Remote Configuration, we can fetch parameters from the Huawei remote configuration and override the default value.

Integration of Remote configuration

1. Configure application on the AGC.

2. Client application development process.

Configure application on the AGC

This step involves the couple of steps, as follows.

Step 1: We need to register as a developer account in AppGallery Connect. If you are already developer ignore this step.

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

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

Step 4: Enabling Remote configuration. Open AppGallery connect, choose Grow > Remote confihuration

Step 5: Generating a Signing Certificate Fingerprint.

Step 6: Configuring the Signing Certificate Fingerprint.

Step 7: Download your agconnect-services.json file, paste it into the app root directory.

Client application development process

This step involves the couple of steps as follows.

Step 1: Create flutter application in the Android studio (Any IDE which is your favorite).

Step 2: Add the 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.

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Step 3: Add the agconnect_remote_config in pubspec.yaml

Step 4: Add downloaded file into outside project directory. Declare plugin path in pubspec.yaml file under dependencies.

dependencies:

flutter:

sdk: flutter

huawei_account:

path: ../huawei_account/

huawei_location:

path: ../huawei_location/

huawei_map:

path: ../huawei_map/

huawei_analytics:

path: ../huawei_analytics/

huawei_site:

path: ../huawei_site/

huawei_push:

path: ../huawei_push/

huawei_dtm:

path: ../huawei_dtm/

agconnect_crash: ^1.0.0

agconnect_remote_config: ^1.0.0

http: ^0.12.2

To achieve Remote configuration service example let us follow the steps.

1. AGC Configuration

2. Build Flutter application

Step 1: AGC Configuration

1. Sign in to AppGallery Connect and select My apps.

2. Select the app in which you want to integrate Huawei Remote configuration Service.

3. Navigate to Grow > Remote configuration

Step 2: Build Flutter application

In this example, I am enabling/Disabling share feature from remote configuration. When share feature is enabled, user can book share cab otherwise user can’t see the share feature

Basically, Huawei Remote Configuration has three different configurations as explained below.

Default Configuration: In this configuration default values defined in your app, if no matching key found on remote configuration sever than default value is copied the in active configuration and returned to the client.

Map<String, dynamic> defaults = {

'enable_feature_share': false,

'button_color': 'red',

'text_color': 'white',

'show_shadow_button': true,

'default_distance': 4.5,

'min_price':80

};

AGCRemoteConfig.instance.applyDefaults(defaults);

Fetched Configuration: Most recent configuration that fetched from the server but not activated yet. We need to activate these configurations parameters, then all value copied in active configuration.

_fetchAndActivateNextTime() async {

await AGCRemoteConfig.instance.applyLastFetched();

Map value = await AGCRemoteConfig.instance.getMergedAll();

setState(() {

_allValue = value;

});

await AGCRemoteConfig.instance.fetch().catchError((error)=>log(error.toString()));

}

Active Configuration: It directly accessible from your app. It contains values either default and fetched.

fetchAndActivateImmediately() async {

await AGCRemoteConfig.instance.fetch().catchError((error)=>log(error.toString()));

await AGCRemoteConfig.instance.applyLastFetched();

Map value = await AGCRemoteConfig.instance.getMergedAll();

setState(() {

_allValue = value;

});

}

Fetch Parameter value

After default parameter values are set or parameter values are fetched from Remote Configuration, you can call AGCRemoteConfig.getValue to obtain the parameter values through key values to use in your app.

_fetchParameterValue(){

AGCRemoteConfig.instance.getValue('enable_feature_share').then((value){

// onSuccess

if(value == 'true'){

_isVisible = true;

}else{

_isVisible =false;

}

}).catchError((error){

// onFailure

});

}

Resetting Parameter Values

You can clear all existing parameter using below function.

_resetParameterValues(){

AGCRemoteConfig.instance.clearAll();

}

What all can be done using Huawei remote configuration

Displaying Different Content to Different Users: Remote Configuration can work with HUAWEI Analytics to personalize content displayed to different audiences. For example, office workers and students will see different products and UI layouts in an app

Adapting the App Theme by Time: You can set time conditions, different app colors, and various materials in Remote Configuration to change the app theme for specific situations. For example, during the graduation season, you can adapt your app to the graduation theme to attract more users.

Releasing New Functions by User Percentage: Releasing new functions to all users at the same time will be risky. Remote Configuration enables new function release by user percentage for you to slowly increase the target user scope, effectively helping you to improve your app based on the feedback from users already exposed to the new functions.

Features of Remote configuration

1. Add parameters

2. Add conditions

1. Adding Parameters: In this you can add parameter with value as many as you want. Later you can also change the value that will be automatically reflected in the app. After adding all the required parameters, lets release the parameter.

2. Adding condition: This feature helps developer to add the conditions based on the below parameters. And conditions can be released.

App Version

OS version

Language

Country/Region

Audience

User Attributes

Predictions

User Percentage

Time

App Version: Condition can be applied on app versions. Which has four operator Include, Exclude, Equal, Include regular expression. Based on these four operators you can add conditions.

OS Version: Using the developer can add condition based on android OS version.

Language: Developer can add the condition based on the language.

Country/Region: Developer can add condition based on the country or region.

User percentage: Developer can roll feature to users based on the percentage of the users between 1-100%.

Time: Developer can use time condition to enable or disable some feature based on time. For example if the feature has to enable on particular day.

After adding required condition, release all the added conditions

View attachment 5283841

Result

View attachment 5283843View attachment 5283845

Tips and Tricks

Download latest HMS Flutter plugin.

Check dependencies downloaded properly.

Latest HMS Core APK is required.

Conclusion

In this article, we have learnt integration of Huawei Remote configuration, how to add the parameters, how to add the Conditions, how to release parameters and conditions and how to fetch the remote data in application and how to clear the data in flutter Taxi booking application.

Reference

Huawei Remote Configuration

Happy coding