checkVersion function

dynamic checkVersion(
  1. String action,
  2. String baseUrl
)

Implementation

checkVersion(String action, String baseUrl) async {
  await 3.delay();
  if (isPhone && isAppDebugFlag) {
    final result =
        await get(baseUrl: "${baseUrl}_${isAndroid ? "apk" : "ipa"}.version");
    if (result.response?.statusCode == 200) {
      final version = result.body["version"] as String;
      if (version.contains("+")) {
        final build = int.parse(version.split("+").last);
        if (Get.context != null && build > int.parse(appBuildNumber)) {
          showBaseAlert(
            BaseGeneralAlertDialog(
              title: Text("新版本"),
              actions: [
                BaseDialogAction(
                  child: Text("立即更新"),
                  onPressed: () async {
                    offBack();
                    final app =
                        isIOS ? "$action$baseUrl.plist" : "$baseUrl.apk";
                    logDebug(app);
                    if (isIOS) {
                      final success = await canLaunch(app);
                      if (success) {
                        onLaunch(app);
                      }
                    } else {
                      onLaunch(app, mode: LaunchMode.externalApplication);
                    }
                  },
                ),
                BaseDialogAction(
                  child: Text("以后再说"),
                  onPressed: () {
                    offBack();
                  },
                ),
              ],
            ),
          );
        }
      }
    }
  }
}