Skip to content

Fixes _shouldUpdate Algorithm#2

Open
undreeyyy wants to merge 2 commits intomix1009:masterfrom
undreeyyy:master
Open

Fixes _shouldUpdate Algorithm#2
undreeyyy wants to merge 2 commits intomix1009:masterfrom
undreeyyy:master

Conversation

@undreeyyy
Copy link

bool _shouldUpdate(String? packageVersion, String? storeVersion) {
if (packageVersion == storeVersion) return false;
final arr1 = packageVersion!.split('.');
final arr2 = storeVersion!.split('.');
for (int i = 0; i < math.min(arr1.length, arr2.length); i++) {
int? v1 = int.tryParse(arr1[i]);
int? v2 = int.tryParse(arr2[i]);
if (v1 == null || v2 == null) {
if (arr2[i].compareTo(arr1[i]) > 0) {
return true;
}
} else if (v2 > v1) {
return true;
}
}
return false;
}

Line 177 - 178 is faulty. This will return true when storeVersion is 5.1.1 and packageVersion is 6.0.0.

My fix will convert the given version from a string to an integer. Such that '6.0.0' will be 600 and '5.1.1' will be 511. Then comparing the 2 integers we can identify the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant