From f25dab2eb8438b3d58c57a023f2e9b10a8e8a1b1 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 15 Oct 2023 20:05:16 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/utils.dart | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 4ccd689a..454ef378 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -187,15 +187,21 @@ class Utils { } // 版本对比 - static bool needUpdate(localVersion, remoteVersion) { - List localVersionList = localVersion.split('.'); - List remoteVersionList = remoteVersion.split('v')[1].split('.'); - for (int i = 0; i < localVersionList.length; i++) { - int localVersion = int.parse(localVersionList[i]); - int remoteVersion = int.parse(remoteVersionList[i]); - if (remoteVersion > localVersion) { + static bool needUpdate(String currentVersion, String remoteVersion) { + List current = currentVersion.split('.').map(int.parse).toList(); + List remote = + remoteVersion.split('v')[1].split('.').map(int.parse).toList(); + + int maxLength = + current.length > remote.length ? current.length : remote.length; + + for (int i = 0; i < maxLength; i++) { + int currentValue = i < current.length ? current[i] : 0; + int remoteValue = i < remote.length ? remote[i] : 0; + + if (currentValue < remoteValue) { return true; - } else if (remoteVersion < localVersion) { + } else if (currentValue > remoteValue) { return false; } }