简体   繁体   English

Firebase 远程配置未更新和使用旧值+ Flutter

[英]Firebase remote config not updating and using older value+ Flutter

When we have a higher version available on the play store.当我们在 Play 商店提供更高版本时。 This feature redirects users to the app store to install updates.此功能将用户重定向到应用商店以安装更新。 But it is not working on a few devices.但它不适用于少数设备。 The user still using the older version.用户仍在使用旧版本。 If the user clears the storage then an alert is displayed.如果用户清除存储,则会显示警报。 We can not ask our users to clear storage.我们不能要求我们的用户清除存储空间。 Any help would be greatly appreciated.任何帮助将不胜感激。

@override
  void initState() {
    super.initState();
    try {
      versionCheck(context);
    } catch (e) {
      print(e);
    }
   }


versionCheck(context) async {
        //Get Current installed version of app
        final PackageInfo info = await PackageInfo.fromPlatform();
        double currentVersion =
            double.parse(info.version.trim().replaceAll(".", ""));
    
        //Get Latest version info from firebase config
        final FirebaseRemoteConfig remoteConfig =
            await FirebaseRemoteConfig.instance;
    
        try {
          // Using default duration to force fetching from remote server.
          await remoteConfig.fetch();
          await remoteConfig.fetchAndActivate();
          remoteConfig.getString('force_update_current_version');
          double newVersion = double.parse(remoteConfig
              .getString('force_update_current_version')
              .trim()
              .replaceAll(".", ""));
          if (newVersion > currentVersion) {
            _showVersionDialog(context);
          }
        } on Exception catch (exception) {
          // Fetch throttled.
          print(exception);
        } catch (exception) {
          print('Unable to fetch remote config. Cached or default values will be '
              'used');
        }
      }

When I tried to print the values I am getting the same values new:160.0 current:160.0, clearing the storage of the app from the setting displays the alert.当我尝试打印这些值时,我得到相同的值 new:160.0 current:160.0,从设置中清除应用程序的存储会显示警报。

I think your code in general looks right to me.我认为您的代码总体上对我来说是正确的。 Though there is a redundant line:虽然有一条多余的线:

remoteConfig.getString('force_update_current_version');

But this should be fine.但这应该没问题。

What I am concerned about is that you replace all your .我担心的是你替换了你所有的. with empty and convert the version to a number.为空并将版本转换为数字。 This can result in a bug if there are two versions like: 1.21.4 vs 1.2.15 .如果有两个版本,如1.21.41.2.15 ,这可能会导致错误。 The first one is supposed to be newer, but the code will get 1214 > 1215 is false第一个应该是更新的,但是代码会得到1214 > 1215 is false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM