check method

Future<UpdateCheckResult> check(
  1. BuildContext context, {
  2. required String url,
  3. UpdateAvailableCallback? onUpdateAvailable,
  4. bool shouldUpdate(
    1. VersionInfo newVersion,
    2. PackageInfo currentPackage
    )?,
  5. Map<String, dynamic>? params,
})

检查更新

流程:请求API → 解析版本 → 判断是否需要更新 → 触发回调或弹窗

Implementation

Future<UpdateCheckResult> check(
  BuildContext context, {
  required String url,
  UpdateAvailableCallback? onUpdateAvailable,
  bool Function(VersionInfo newVersion, PackageInfo currentPackage)?
  shouldUpdate,
  Map<String, dynamic>? params,
}) {
  if (!Platform.isAndroid) {
    return Future.value(const UpdateUnsupported());
  }
  _ensureInitialized();

  final runningCheck = _checkInProgress;
  if (runningCheck != null) return runningCheck;

  if (statusNotifier.value == DownloadStatus.downloading ||
      statusNotifier.value == DownloadStatus.paused) {
    final requestId = ++_checkSequence;
    return Future.value(
      _handleCheckFailure(
        const UpgraderException(
          type: UpdateCheckFailureType.busy,
          message: 'A download is active. Reset it before checking again.',
        ),
        requestId: requestId,
      ),
    );
  }

  final requestId = ++_checkSequence;
  late final Future<UpdateCheckResult> operation;
  operation =
      _performCheck(
        context,
        requestId: requestId,
        url: url,
        onUpdateAvailable: onUpdateAvailable,
        shouldUpdate: shouldUpdate,
        params: params,
      ).whenComplete(() {
        if (identical(_checkInProgress, operation)) {
          _checkInProgress = null;
        }
      });
  _checkInProgress = operation;
  return operation;
}