bool compareVersion({required String appVersion, required String compareVersion}) {
  bool isNeedUpdate = false;
  List<String> arrX = appVersion.split(".");
  List<String> arrY = compareVersion.split(".");

  int length = max(arrX.length, arrY.length);

  for (int i = 0; i < length; i++) {
    int x, y;

    try {
      x = int.parse(arrX[i]);
    } on Exception {
      x = 0;
    }

    try {
      y = int.parse(arrY[i]);
    } on Exception {
      y = 0;
    }

    if (x > y) {
      //앱버전이큼
      isNeedUpdate = false;
      break;
    } else if (x < y) {
      //비교버전이큼
      isNeedUpdate = true;
      break;
    } else {
      //동일
      isNeedUpdate = false;
    }
  }

  return isNeedUpdate;
}
반응형

+ Recent posts