From a2d0e733d37f4a818206a1d32d7659b9f1701b46 Mon Sep 17 00:00:00 2001 From: "DESKTOP-I3JPKHK\\wy" <1111> Date: Tue, 16 Dec 2025 21:28:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BB=8E=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=89=8D=E5=8F=B0=E5=90=8E=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app_upgrade_simple.dart | 23 +++++++++++++++-------- pubspec.yaml | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/app_upgrade_simple.dart b/lib/app_upgrade_simple.dart index ed4a7a7..259bd30 100644 --- a/lib/app_upgrade_simple.dart +++ b/lib/app_upgrade_simple.dart @@ -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 on State { 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 = false; + } + debugPrint( + '📊 构建号比较: $currentBuildNumber vs ${info.versionBuildNumber}, 版本比较(如需): ${info.versionName} -> $isUpdated'); } else { - isUpdated = currentVersion == info.versionName; - debugPrint('📊 版本号比较: $currentVersion == ${info.versionName} = $isUpdated'); + isUpdated = AppUpgradeSimple.compareVersionStrings(currentVersion, info.versionName) > 0; + debugPrint('📊 版本号比较: $currentVersion vs ${info.versionName} = $isUpdated'); } if (isUpdated) { diff --git a/pubspec.yaml b/pubspec.yaml index e7b7107..fe3c5b3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: