getDataType function

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

Implementation

String getDataType(v, Set<String> set, String current, String 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) {
    // handle other type that is not built-in
    if (v.startsWith("$tag[]")) {
      final 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)) {
      final 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";
  }
}