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
- Install flutter environment
a) Download the Flutter sdk package, address: https://flutter.dev/docs/get-started/install/windows .
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.
- Open service & create project
a) Create an Android project in AGC and activate the remote configuration service.
b) Add the following configuration items in the remote configuration.
c) Click "File-New-New Flutter Project..." in Android Studio to create a new Flutter project.
d) On the AGC "Project Settings" page, find the application menu to download the agconnect-services.json file.
e) Put the agconnect-services.json file into the location in the directory below.
f) Make the following maven warehouse and remote configuration plug-in configuration in the application-level build.gradle file.
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.
- Integrated SDK
Add remote configuration pub dependency in pubspec.yaml file
Then click Pub get to synchronize
- basic skills
Here I have implemented a simple demo application to demonstrate several main functions.
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
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:
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:
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.
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
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