12345678910111213141516171819202122232425262728293031 |
- import 'package:sport/services/Converter.dart';
- List<int> version(String versionName) {
- if (versionName.isEmpty == true) return [0, 0, 0];
- var arr = versionName.split(".");
- while (arr.length < 3) arr.add("0");
- return arr.map((e) => Converter.toInt(e)).toList();
- }
- /**
- * v1: local
- * v2: net
- */
- int versionCompare(String v1, String v2) {
- if (v1 == v2) return 0;
- var clientVersion = version(v1);
- var baseVersion = version(v2);
- int client =
- (clientVersion[0] << 20) | (clientVersion[1] << 10) | clientVersion[2];
- int base = (baseVersion[0] << 20) | (baseVersion[1] << 10) | baseVersion[2];
- int result = 0;
- if (client > base) {
- result = 1;
- } else if (client == base) {
- result = 0;
- } else {
- result = -1;
- }
- print("versionCompare $clientVersion $baseVersion == $result");
- return result;
- }
|