bestCriticalItem method

AppCastItem? bestCriticalItem()

Returns the latest critical item in the Appcast.

Implementation

AppCastItem? bestCriticalItem() {
  if (items == null) {
    return null;
  }

  AppCastItem? bestItem;
  for (var item in items!) {
    if (item.hostSupportsItem(
            osVersion: osVersionString,
            currentPlatform: hcUpgradeOS.current) &&
        item.isCriticalUpdate) {
      if (bestItem == null) {
        bestItem = item;
      } else {
        try {
          final itemVersion = Version.parse(item.versionString!);
          final bestItemVersion = Version.parse(bestItem.versionString!);
          if (itemVersion > bestItemVersion) {
            bestItem = item;
          }
        } on Exception catch (e) {
          if (kDebugMode) {
            print('hcUpgrade: criticalUpdateItem invalid version: $e');
          }
        }
      }
    }
  }
  return bestItem;
}