getType function

String getType(
  1. dynamic v,
  2. Set<String> set,
  3. String current,
  4. dynamic tag,
)

Implementation

String getType(v,Set<String> set,String current, tag){
  current = current.toLowerCase();
  if(v is bool){
    return "bool";
  }else if(v is num){
    return "num";
  }else if(v is Map){
    return "Map<String,dynamic>";
  }else if(v is List){
    return "List";
  }else if(v is String){ //处理特殊标志
    if(v.startsWith("$tag[]")){
      var type = changeFirstChar(v.substring(3),false);
      if(type.toLowerCase() != current&&!isBuiltInType(type)) {
        set.add('import "$type.dart"');
      }
      return "List<${changeFirstChar(type)}>";

    }else if(v.startsWith(tag)){
      var fileName = changeFirstChar(v.substring(1),false);
      if(fileName.toLowerCase()!= current) {
        set.add('import "$fileName.dart"');
      }
      return changeFirstChar(fileName);
    }else if(v.startsWith("@")){
      return v;
    }
    return "String";
  }else{
    return "String";
  }
}