checkWindowsUpdate method

Future<bool> checkWindowsUpdate(
  1. Map<String, dynamic> windowsData,
  2. PackageInfo packageInfo,
  3. bool allowSkip,
  4. BuildContext context,
  5. DownloadState downloadState,
  6. UpdateCenterConfig config,
  7. String downloadUrl,
)

Checks for an available update for Windows platform and shows update dialog if necessary.

Implementation

Future<bool> checkWindowsUpdate(
  Map<String, dynamic> windowsData,
  PackageInfo packageInfo,
  bool allowSkip,
  BuildContext context,
  DownloadState downloadState,
  UpdateCenterConfig config,
  String downloadUrl,
) async {
  WindowsModel model = WindowsModel(
    windowsData['versionName'],
    windowsData['downloadUrl'],
    windowsData['changeLog'],
    windowsData['sourceUrl'],
    windowsData['versionCode'],
    windowsData['minSupport'],
  );

  int buildNumber = int.parse(packageInfo.buildNumber);

  if (model.minSupport > buildNumber) {
    allowSkip = false; // Update is mandatory
  }

  // Check if the current build number is less than the update version code
  if (buildNumber < model.versionCode) {
    // Get the stored version info
    String? storedVersion = await MemoryProvider.getVersionInfoWindows();

    // Compare with the new version
    if (storedVersion != null && storedVersion != model.versionName) {
      // Versions differ, delete the old file and stored version info
      MemoryProvider.deleteFileDirectoryWindows();
    }

    // Save the new version info
    await MemoryProvider.saveVersionInfoWindows(model.versionName);

    if (context.mounted && config.globalConfig.windowsDialogBuilder != null) {
      await config.globalConfig.windowsDialogBuilder!(
          context,
          model, // Assume this is your AndroidModel instance with update info
          config,
          downloadState, // Your DownloadState instance
          allowSkip);
    }

    downloadUrl = model.downloadUrl; // Set the download URL
    return true; // Return true to indicate that an update is available
  }

  if (buildNumber >= model.versionCode) {
    if (config.globalConfig.isNoUpdateAvailableToast) {
      if (config.globalConfig.isNoUpdateAvailableToast && config.globalConfig.windowsNoUpdateAvailableBuilder != null) {
        config.globalConfig.windowsNoUpdateAvailableBuilder?.call(context);
      }
    }
    MemoryProvider.deleteFileDirectoryWindows();
    return false;
  }
  return false; // No update available
}