checkForUpdate static method

Future<AppUpdateInfo> checkForUpdate()

Has to be called before being able to start any update.

Returns AppUpdateInfo, which can be used to decide if startFlexibleUpdate or performImmediateUpdate should be called.

Implementation

static Future<AppUpdateInfo> checkForUpdate() async {
  final result = await _channel.invokeMethod('checkForUpdate');

  return AppUpdateInfo(
    updateAvailability: UpdateAvailability.values.firstWhere(
        (element) => element.value == result['updateAvailability']),
    immediateUpdateAllowed: result['immediateAllowed'],
    immediateAllowedPreconditions: result['immediateAllowedPreconditions']
        ?.map<int>((e) => e as int)
        .toList(),
    flexibleUpdateAllowed: result['flexibleAllowed'],
    flexibleAllowedPreconditions: result['flexibleAllowedPreconditions']
        ?.map<int>((e) => e as int)
        .toList(),
    availableVersionCode: result['availableVersionCode'],
    installStatus: InstallStatus.values
        .firstWhere((element) => element.value == result['installStatus']),
    packageName: result['packageName'],
    clientVersionStalenessDays: result['clientVersionStalenessDays'],
    updatePriority: result['updatePriority'],
  );
}