处理从后台返回前台后检查版本号方法

This commit is contained in:
DESKTOP-I3JPKHK\wy 2025-12-16 21:28:25 +08:00
parent c497e72f57
commit a2d0e733d3
2 changed files with 16 additions and 9 deletions

View File

@ -378,13 +378,13 @@ class AppUpgradeSimple {
hasUpdate = true;
} else if (versionBuildNumber == currentBuildNumber) {
// buildNumber
if (versionName != null && _compareVersionStrings(versionName, currentVersionName) > 0) {
if (versionName != null && compareVersionStrings(versionName, currentVersionName) > 0) {
hasUpdate = true;
}
}
} else {
//
if (versionName != null && _compareVersionStrings(versionName, currentVersionName) > 0) {
if (versionName != null && compareVersionStrings(versionName, currentVersionName) > 0) {
hasUpdate = true;
}
}
@ -480,7 +480,7 @@ class AppUpgradeSimple {
return await _plugin.getAppInfo();
}
int _compareVersionStrings(String v1, String v2) {
static int compareVersionStrings(String v1, String v2) {
try {
final v1Parts = v1.split('.').map((e) => int.tryParse(e) ?? 0).toList();
final v2Parts = v2.split('.').map((e) => int.tryParse(e) ?? 0).toList();
@ -877,13 +877,20 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
debugPrint('📱 当前版本: $currentVersion, 构建号: $currentBuildNumber');
debugPrint('🎯 目标版本: ${info.versionName}, 构建号: ${info.versionBuildNumber}');
bool isUpdated = false;
bool isUpdated;
if (info.versionBuildNumber > 0) {
isUpdated = currentBuildNumber >= info.versionBuildNumber;
debugPrint('📊 构建号比较: $currentBuildNumber >= ${info.versionBuildNumber} = $isUpdated');
if (currentBuildNumber > info.versionBuildNumber) {
isUpdated = true;
} else if (currentBuildNumber == info.versionBuildNumber) {
isUpdated = AppUpgradeSimple.compareVersionStrings(currentVersion, info.versionName) > 0;
} else {
isUpdated = currentVersion == info.versionName;
debugPrint('📊 版本号比较: $currentVersion == ${info.versionName} = $isUpdated');
isUpdated = false;
}
debugPrint(
'📊 构建号比较: $currentBuildNumber vs ${info.versionBuildNumber}, 版本比较(如需): ${info.versionName} -> $isUpdated');
} else {
isUpdated = AppUpgradeSimple.compareVersionStrings(currentVersion, info.versionName) > 0;
debugPrint('📊 版本号比较: $currentVersion vs ${info.versionName} = $isUpdated');
}
if (isUpdated) {

View File

@ -1,6 +1,6 @@
name: yx_app_upgrade_flutter
description: "A universal, robust, and high-performance Flutter app upgrade plugin with smart update features."
version: 1.0.1
version: 1.0.2
homepage: https://github.com/yourusername/yx_app_upgrade_flutter
environment: