resolve static method
Builds the answer for a client on currentVersion and channel, given
the newest release the registry would offer it.
The rules:
- No offerable release at all → not an error,
updateAvailable: false. A package with only drafts is a real state, not a failure. latestnot strictly newer thancurrentVersion→false. Equal versions are current; an older registry version means the client is ahead (a developer on a local build), and offering a downgrade would be worse than saying nothing.- Otherwise →
true, carrying the release and the asset matchingplatform.
Comparison uses Versions.compare, so 1.0.0+build2 is correctly newer
than 1.0.0+build1 — semver calls those equal, which would strand a fleet
on a broken build of the same version.
Implementation
static UpdateInfo resolve({
required String packageName,
required Version currentVersion,
required ReleaseChannel channel,
Release? latest,
List<Asset> assets = const [],
String? platform,
}) {
if (latest == null) {
return UpdateInfo.upToDate(
currentVersion: currentVersion,
channel: channel,
packageName: packageName,
);
}
final isNewer = Versions.compare(latest.version, currentVersion) > 0;
if (!isNewer) {
return UpdateInfo.upToDate(
currentVersion: currentVersion,
channel: channel,
packageName: packageName,
latestVersion: latest.version,
release: latest,
);
}
return UpdateInfo(
currentVersion: currentVersion,
latestVersion: latest.version,
updateAvailable: true,
channel: channel,
release: latest,
asset: selectAsset(assets, platform: platform),
packageName: packageName,
notes: latest.notes,
);
}