initialize method

Future<bool> initialize()

Initialize HcUpgradeNewVersion by getting saved preferences, getting platform package info, and getting released version info.

Implementation

Future<bool> initialize() async {
  if (debugLogging) {
    if (kDebugMode) {
      print('hcUpgrade: initialize called');
    }
  }
  if (_futureInit != null) return _futureInit!;

  _futureInit = Future(() async {
    if (debugLogging) {
      if (kDebugMode) {
        print('hcUpgrade: initializing');
      }
    }
    if (_initCalled) {
      assert(false, 'This should never happen.');
      return true;
    }
    _initCalled = true;

    await getSavedPrefs();

    if (debugLogging) {
      if (kDebugMode) {
        print('hcUpgrade: default operatingSystem: '
          '${upgradeOS.operatingSystem} ${upgradeOS.operatingSystemVersion}');
        print('hcUpgrade: operatingSystem: ${upgradeOS.operatingSystem}');
        print('hcUpgrade: '
          'isAndroid: ${upgradeOS.isAndroid}, '
          'isIOS: ${upgradeOS.isIOS}, '
          'isLinux: ${upgradeOS.isLinux}, '
          'isMacOS: ${upgradeOS.isMacOS}, '
          'isWindows: ${upgradeOS.isWindows}, '
          'isFuchsia: ${upgradeOS.isFuchsia}, '
          'isWeb: ${upgradeOS.isWeb}');
      }
    }

    if (_packageInfo == null) {
      _packageInfo = await PackageInfo.fromPlatform();
      if (debugLogging) {
        if (kDebugMode) {
          print(
            'hcUpgrade: package info packageName: ${_packageInfo!.packageName}');
          print('hcUpgrade: package info appName: ${_packageInfo!.appName}');
          print('hcUpgrade: package info version: ${_packageInfo!.version}');
        }
      }
    }

    _installedVersion = _packageInfo!.version;

    await updateVersionInfo();

    // Add an observer of application events.
    WidgetsBinding.instance.addObserver(this);

    _evaluationReady = true;

    /// Trigger the stream to indicate an evaluation should be performed.
    /// The value will always be true.
    _streamController.add(true);

    return true;
  });
  return _futureInit!;
}