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 = lowerChar(v.substring(3));
      if (type.toLowerCase() != current && !isBuiltInType(type)) {
        set.add('import "$type.dart"');
      }
      return "List<${upperChar(type)}>";
    } else if (v.startsWith(tag)) {
      final fileName = lowerChar(v.substring(1));
      if (fileName.toLowerCase() != current) {
        set.add('import "$fileName.dart"');
      }
      return upperChar(fileName);
    } else if (v.startsWith("@")) {
      return v;
    }
    return "String";
  } else {
    return "String";
  }
}