简体   繁体   中英

Firebase remote config not updating and using older value+ Flutter

When we have a higher version available on the play store. 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.

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 . The first one is supposed to be newer, but the code will get 1214 > 1215 is false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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