checkForUpdate function

Future<VersionConfig?> checkForUpdate()

Checks whether the running app version is older than the version declared in Remote Config.

Returns null when Firebase is disabled, the config key is absent, or the app is already up to date — regardless of isForceUpdate. Returns a VersionConfig record (with isForcedUpdate set accordingly) when the running version is outdated, covering both forced and optional update scenarios.

Implementation

Future<VersionConfig?> checkForUpdate() async {
  final config = _parseVersionConfig();
  if (config == null) return null;

  final currentVersion = await getCurrentSemVer();

  if (isVersionOlder(currentVersion, config.requiredVersion)) {
    log(
      '${config.isForcedUpdate ? 'Force' : 'Optional'} update available: '
      'current=$currentVersion, required=${config.requiredVersion}',
      name: 'UpdateService',
    );
    return config;
  }

  return null;
}