当前位置:网站首页>How to integrate Huawei remote configuration service in flutter

How to integrate Huawei remote configuration service in flutter

2020-11-10 18:08:32 Huawei Developer Forum

The recent discovery AGC The first part of the service has started to support third-party frameworks , These include Flutter, So I tried a remote configuration experiment with a small scalpel .

Integration steps

  1. install flutter Environmental Science

  a) download Flutter sdk package , Address :https://flutter.dev/docs/get-started/install/windows.

 Insert picture description here

Unzip the package to any folder , for example D:\Flutter

  b) take Flutter Add to environment variable , Here I add Path by D:\Flutter\flutter_windows_1.22.2-stable\flutter\bin.

  c) stay Android Studio Click on the “File-Settings-Plugins”, download Flutter and Dart plug-in unit , restart Android Studio Make plug-ins work .

 Insert picture description here

  1. Opening service & Create a project

  a) stay AGC establish Android Project and open remote configuration service .

 Insert picture description here

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

 Insert picture description here

  c) stay Android Studio Click on the “File-New-New Flutter Project…”, newly build Flutter engineering .

 Insert picture description here

  d) stay AGC“ Project settings ” page , Find the application menu and download agconnect-services.json file .

 Insert picture description here

  e) take agconnect-services.json The file is placed in the following directory .

 Insert picture description here

  f) At the application level build.gradle In the document, it is made as follows maven Warehouse and remote configuration plug-in configuration .

 Insert picture description here

  g) open Flutter project android/app Under folder build.gradle file , Add compilation dependencies and AGC Plug-in address .

 Insert picture description here

  1. Integrate SDK

stay pubspec.yaml Add remote configuration to the file pub rely on  Insert picture description here

And then click Pub get To synchronize  Insert picture description here

  1. Basic function

Here I've implemented a simple demo The main functions are demonstrated in several applications .

 Insert picture description here

UI In design , It has been described as “Mode 1:Fetch And Activate Immediately”、“Mode 2:Fetch And Activate Next Time”、“Clear Data” Three buttons , Can achieve the following main functions .

  a) Get cloud data , This time it comes into effect

 Insert picture description here  Insert picture description here

Click on “Mode 1:Fetch And Activate Immediately” Button , call fetch Call directly after applyLastFetched To get this fetch Data to . Since it is effective immediately , So we call getMergedAll Interface to apply all configuration locally , We can get data from the cloud on mobile phones , Click the effect as follows :

 Insert picture description here

  b) Get cloud data , Take effect the configuration obtained last time

The implementation interface of deferred effect is the same as that of immediate effect , It's just that the order is different :

 Insert picture description here

Click on “Mode 2:Fetch And Activate Next Time” Button , Will first apply and getMergedAll To apply the last time fetch Result , Call again fetch To get the latest configuration for next use .

  c) Clear data

If you want to clear the data , Just click “Clear Data”, call clearAll The interface will do .

 Insert picture description here

  d) Set the local configuration item

We can pass in dart Create a new Map Parameters of type , And then call applyDefault Interface to apply local configuration :

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

  e) pack

And Android identical , Only need Android Studio Click to run

 Insert picture description here

matters needing attention

And in Android Platform settings local configuration items The difference is ,Flutter Can't use xml File to store local configuration items .

For more details , Please see the :

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

How to be in Android Platform integration remote configuration service : https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-remoteconfig-introduction


Link to the original text : https://developer.huawei.com/consumer/cn/forum/topic/0201399745099710131?fid=0101271690375130218 author : Drum Tower Zhao Youting

版权声明
本文为[Huawei Developer Forum]所创,转载请带上原文链接,感谢