hostSupportsItem method

bool hostSupportsItem({
  1. String? osVersion,
  2. required String currentPlatform,
})

Does the host support this item? If so is osVersion supported?

Implementation

bool hostSupportsItem({String? osVersion, required String currentPlatform}) {
  assert(currentPlatform.isNotEmpty);
  bool supported = true;
  if (osString != null && osString!.isNotEmpty) {
    final platformEnum = 'TargetPlatform.${osString!}';
    currentPlatform = 'TargetPlatform.$currentPlatform';
    supported = platformEnum.toLowerCase() == currentPlatform.toLowerCase();
  }

  if (supported && osVersion != null && osVersion.isNotEmpty) {
    Version osVersionValue;
    try {
      osVersionValue = Version.parse(osVersion);
    } catch (e) {
      if (kDebugMode) {
        print('hcUpgrade: hostSupportsItem invalid osVersion: $e');
      }
      return false;
    }
    if (maximumSystemVersion != null) {
      try {
        final maxVersion = Version.parse(maximumSystemVersion!);
        if (osVersionValue > maxVersion) {
          supported = false;
        }
      } on Exception catch (e) {
        if (kDebugMode) {
          print('hcUpgrade: hostSupportsItem invalid maximumSystemVersion: $e');
        }
      }
    }
    if (supported && minimumSystemVersion != null) {
      try {
        final minVersion = Version.parse(minimumSystemVersion!);
        if (osVersionValue < minVersion) {
          supported = false;
        }
      } on Exception catch (e) {
        if (kDebugMode) {
          print('hcUpgrade: hostSupportsItem invalid minimumSystemVersion: $e');
        }
      }
    }
  }
  return supported;
}