getResponseClass method

String getResponseClass(
  1. String suffix,
  2. String name,
  3. String parent,
  4. Map? map, [
  5. bool root = false,
])

Implementation

String getResponseClass(String suffix, String name, String parent, Map? map,
    [bool root = false]) {
  if (map == null) return '';
  final apiClassName = ModelClassNameHelper.getClassName(
      listClassNameResponse, suffix, name, root, true, parent);
  final classString = '''class $apiClassName extends Equatable {
${setConstractor(apiClassName, map)}

${fromMap(apiClassName, map, suffix, listClassNameResponse, apiClassName)}

factory $apiClassName.fromJson(String source) =>
    $apiClassName.fromMap(json.decode(source));

${setTypeData(map, suffix, listClassNameResponse, apiClassName)}

${toMap(map)}

String toJson() => json.encode(toMap());

${setPropsEquatable(map)}
}

${map.keys.map((e) => map[e] is Map ? getResponseClass(suffix, e.toString().pascalCase, apiClassName, map[e]) : '').join()}
${map.keys.map((e) => map[e] is List ? map[e] == null ? '' : (map[e] as List).isEmpty ? '' : (map[e] as List).first is! Map ? '' : getResponseClass(suffix, e.toString().pascalCase, apiClassName, (map[e] as List).first) : '').join()}
''';

  return classString;
}