check method
Future<UpdateCheckResult>
check(
- BuildContext context, {
- required String url,
- UpdateAvailableCallback? onUpdateAvailable,
- bool shouldUpdate(
- VersionInfo newVersion,
- PackageInfo currentPackage
- 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;
}