美文网首页
Flutter 更新判断

Flutter 更新判断

作者: 陈晓青_57a8 | 来源:发表于2019-08-22 19:09 被阅读0次

///规则是:

//先比较第一位和第二位

//第一位或第二位大于旧版本,就强制更新,

//否则就比较第三位

//第三位决定是否提示更新,非强制

const int MANDATORY =0; //强制更新

const int REMIND =1; //提示更新

const int NOT =2; //不更新

const int ERROR = -1; //不更新

Future shouldUpdate(String version)async {

String currentVersion ='5.1.0';

  List newVersion = version.split('.').map((f) {

return int.parse(f);

  }).toList();

  List oldVersion = currentVersion.split('.').map((f) {

return int.parse(f);

  }).toList();

  if (newVersion !=null &&

newVersion.length ==3 &&

oldVersion !=null &&

oldVersion.length ==3) {

if (oldVersion[0] < newVersion[0]) {

//旧版本1 < 新版本1

      return MANDATORY; //强制更新

    }

if (oldVersion[0] == newVersion[0]) {

if (oldVersion[1] < newVersion[1]) {

return MANDATORY;

      }

}

if (oldVersion[0] == newVersion[0] && oldVersion[1] == newVersion[1]) {

if (oldVersion[2] < newVersion[2]) {

return REMIND;

      }

}

return NOT;

  }

}

相关文章

网友评论

      本文标题:Flutter 更新判断

      本文链接:https://www.haomeiwen.com/subject/lxposctx.html