updateVersionInfo method

Future<UpgraderVersionInfo?> updateVersionInfo()

Update the version info for this app by using an UpgraderStore to get the UpgraderVersionInfo.

Implementation

Future<UpgraderVersionInfo?> updateVersionInfo() async {
  if (state.packageInfo == null || state.packageInfo!.packageName.isEmpty) {
    updateState(state.copyWithNull(versionInfo: null));
    return null;
  }

  // Determine the store to be used for this app.
  final store = storeController.getUpgraderStore(state.upgraderOS);
  if (store == null) {
    if (state.debugLogging) {
      print('upgrader: updateVersionInfo found no store controller');
    }
    updateState(state.copyWithNull(versionInfo: null));
    return null;
  }

  // Determine the installed version of this app.
  late Version installedVersion;
  try {
    installedVersion = Version.parse(state.packageInfo!.version);
  } catch (e) {
    if (state.debugLogging) {
      print('upgrader: installedVersion exception: $e');
    }
    updateState(state.copyWithNull(versionInfo: null));
    return null;
  }

  final locale = findLocale();

  // Determine the country code of the locale, defaulting to `US`.
  final country =
      state.countryCodeOverride ?? findCountryCode(locale: locale);
  if (state.debugLogging) {
    print('upgrader: countryCode: $country');
  }

  // Determine the language code of the locale, defaulting to `en`.
  final language =
      state.languageCodeOverride ?? findLanguageCode(locale: locale);
  if (state.debugLogging) {
    print('upgrader: languageCode: $language');
  }

  // Get the version info from the store.
  final versionInfo = await store.getVersionInfo(
      state: state,
      installedVersion: installedVersion,
      country: country,
      language: language);

  updateState(state.copyWith(versionInfo: versionInfo));

  return versionInfo;
}