How to integrate Huawei remote configuration service in Flutter

Recently, it was discovered that some services on AGC began to support third-party frameworks, including Flutter, so I tried a little bit of experimentation on remote configuration.

Integration steps

  1. Install flutter environment

  a) Download the Flutter sdk package, address: https://flutter.dev/docs/get-started/install/windows .

Insert picture description here

Unzip the compressed package to any folder, such as D:\Flutter

  b) Add Flutter to the environment variable. Here, the Path I added is D:\Flutter\flutter_windows_1.22.2-stable\flutter\bin.

  c) Click "File-Settings-Plugins" in Android Studio, download the Flutter and Dart plug-ins, and restart Android Studio to make the plug-ins take effect.

Insert picture description here

  1. Open service & create project

  a) Create an Android project in AGC and activate the remote configuration service.

Insert picture description here

  b) Add the following configuration items in the remote configuration.

Insert picture description here

  c) Click "File-New-New Flutter Project..." in Android Studio to create a new Flutter project.

Insert picture description here

  d) On the AGC "Project Settings" page, find the application menu to download the agconnect-services.json file.

Insert picture description here

  e) Put the agconnect-services.json file into the location in the directory below.

Insert picture description here

  f) Make the following maven warehouse and remote configuration plug-in configuration in the application-level build.gradle file.

Insert picture description here

  g) Open the build.gradle file in the android/app folder of the Flutter project, and add the compilation dependencies and the AGC plug-in address.

Insert picture description here

  1. Integrated SDK

Add remote configuration pub dependency in pubspec.yaml file
Insert picture description here

Then click Pub get to synchronize
Insert picture description here

  1. basic skills

Here I have implemented a simple demo application to demonstrate several main functions.

Insert picture description here

In the UI design, there are three buttons described as "Mode 1: Fetch And Activate Immediately", "Mode 2: Fetch And Activate Next Time", and "Clear Data", which can achieve the following main functions.

  a) Get cloud data, effective this time

Insert picture description here
Insert picture description here

Click the "Mode 1: Fetch And Activate Immediately" button, call applyLastFetched directly after calling the fetch to get the data obtained this time. Since it takes effect immediately, we call the getMergedAll interface to apply all configurations locally, and we can get the cloud data on the mobile phone. The effect of clicking is as follows:

Insert picture description here

  b) Obtain cloud data and validate the configuration obtained last time

The implementation interface of delayed effective is the same as immediate effective, but the order is different:

Insert picture description here

Click the "Mode 2: Fetch And Activate Next Time" button, apply and getMergedAll will first apply the results of the last fetch, and then call fetch to get the latest configuration for next use.

  c) Clear data

If you want to clear the data, just click "Clear Data" and call the clearAll interface.

Insert picture description here

  d) Set local configuration items

We can apply the local configuration by creating a new Map type parameter in the dart file, and then calling the applyDefault interface:

Map defaults = {    
    'mLong': 1000,    
    'mString': 'hello world',    
    'mDouble': 3.14,    
    'mBoolean': true
};
AGCRemotConfig.instance.applyDefaults(defaults);

  e) Packaging

Same as Android, just click to run in Android Studio

Insert picture description here

Precautions

Unlike setting local configuration items on the Android platform , Flutter cannot use xml files to store local configuration items.

For more details, please see:

Flutter official guidance document:
https://flutter.dev/docs/get-started/install/windows

How to integrate remote configuration services on the Android platform:
https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-remoteconfig-introduction


Original link:
https://developer.huawei.com/consumer/cn/forum/topic/0201399745099710131?fid=0101271690375130218
Author: Drum Chao

Guess you like

Origin blog.51cto.com/14772288/2548871