Skip to content

Instantly share code, notes, and snippets.

@tearf001
Created April 8, 2019 01:53
Show Gist options
  • Save tearf001/9c22f58fd6bae991396940c25065d81e to your computer and use it in GitHub Desktop.
Save tearf001/9c22f58fd6bae991396940c25065d81e to your computer and use it in GitHub Desktop.
版本检查 dart
String deversion(String version){
if(version == null || version.compareTo("1.0.0")<0) return version;
var versions = version.split('.');
var s = int.parse(versions.first) -1;
versions[0] = s.toString();
return versions.join('.');
}
int versionValue(String version){
if(version == null) return null;
var versions = version.split('.');
var v = 0;
for(var i =0;i < versions.length ;i++){
v = v *10 + int.parse(versions[i]);
}
return v;
}
main(){
var c = [{"2":3}];
print('$c is Map? ${c is Map}');
assert(c.first['type']==null);
print('[type]is what? ${c.first["type"] ??"o"}');
var version = [null,"0.1.1","1.2.3"];
print('12.1 对比 9.9 ${"12.1".compareTo("9.9")}');
version.forEach((s)=>print('$s=>${deversion(s)} | ${versionValue(s)}'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment