getVersionInfo method
Future<UpgraderVersionInfo>
getVersionInfo({
- required UpgraderState state,
- required Version installedVersion,
- required String? country,
- required String? language,
override
Implementation
@override
Future<UpgraderVersionInfo> getVersionInfo(
{required UpgraderState state,
required Version installedVersion,
required String? country,
required String? language}) async {
String? appStoreListingURL;
Version? appStoreVersion;
bool? isCriticalUpdate;
String? releaseNotes;
final localAppcast = appcast ??
Appcast(
client: state.client,
clientHeaders: state.clientHeaders,
upgraderDevice: state.upgraderDevice,
upgraderOS: state.upgraderOS);
await localAppcast.parseAppcastItemsFromUri(appcastURL);
if (state.debugLogging) {
var count = localAppcast.items == null ? 0 : localAppcast.items!.length;
print('upgrader: UpgraderAppcastStore item count: $count');
}
final criticalUpdateItem = localAppcast.bestCriticalItem();
final criticalVersion = criticalUpdateItem?.versionString ?? '';
final bestItem = localAppcast.bestItem();
if (bestItem != null &&
bestItem.versionString != null &&
bestItem.versionString!.isNotEmpty) {
if (state.debugLogging) {
print('upgrader: UpgraderAppcastStore best item version: '
'${bestItem.versionString}');
print('upgrader: UpgraderAppcastStore critical update item version: '
'${criticalUpdateItem?.versionString}');
}
try {
if (criticalVersion.isNotEmpty &&
installedVersion < Version.parse(criticalVersion)) {
isCriticalUpdate = true;
}
} catch (e) {
if (state.debugLogging) {
print(
'upgrader: UpgraderAppcastStore: getVersionInfo could not parse version info $e');
}
}
if (bestItem.versionString != null) {
try {
appStoreVersion = Version.parse(bestItem.versionString!);
} catch (e) {
if (state.debugLogging) {
print(
'upgrader: UpgraderAppcastStore: best item version could not be parsed: '
'${bestItem.versionString}');
}
}
}
appStoreListingURL = bestItem.fileURL;
releaseNotes = bestItem.itemDescription;
}
final versionInfo = UpgraderVersionInfo(
installedVersion: installedVersion,
appStoreListingURL: appStoreListingURL,
appStoreVersion: appStoreVersion,
isCriticalUpdate: isCriticalUpdate,
releaseNotes: releaseNotes,
);
if (state.debugLogging) {
print('upgrader: UpgraderAppcastStore: version info: $versionInfo');
}
return versionInfo;
}