convert method

void convert()

convert is a main method of ConvertJsonSerializableMode class

Implementation

void convert() {
  /// clear .dart files list
  files.clear();

  /// files variables
  final allFilesVariables =
      JsonConvertUtils.variablesDeclare(json, name: className);

  final allFilesImports =
      JsonConvertUtils.importClasses(json, className: className);

  for (final entry in allFilesVariables) {
    /// get variables
    final variables = entry.value;
    final imports =
        allFilesImports.firstWhere((element) => element.key == entry.key);
    final fileName = entry.key;

    files.add(MapEntry(
        entry.key, '''import 'package:json_annotation/json_annotation.dart';
${options.equatableMixin ? "import 'package:equatable/equatable.dart';" : ""}
${imports.value.map((e) => "import '../$e/$e.dart';").join("\n")}
${"part '${fileName.snakeCase}.g.dart';"}

@JsonSerializable()
class ${fileName.pascalCase} ${options.equatableMixin ? "with EquatableMixin" : ""}{
${"${_defaultVariables(variables).join(";\n  ")};"}

${fileName.pascalCase}({
 ${_variablesInsideParentheses(variables).join(",\n   ")},
});
${options.equatableMixin ? '''

@override
List<Object?> get props =>
    [${variables.names.join(", ")}];''' : ""}

${options.copyWith ? '''
${fileName.pascalCase} copyWith({
  ${_copyWithParentheses(variables).join(",\n    ")},
}) {
  return ${fileName.pascalCase}(
    ${_copyWith(variables).join(",\n      ")},
  );
}''' : ""}

factory ${fileName.pascalCase}.fromJson(Map<String, dynamic> json) =>
    _\$${fileName.pascalCase}FromJson(json);

Map<String, dynamic> toJson() => _\$${fileName.pascalCase}ToJson(this);

@override
String toString() =>
    "${fileName.pascalCase}(${variables.names.map((e) => "$e: \$$e").toList().join(", ")},)";

@override
int get hashCode =>
    Object.hash(${variables.names.join(", ")},);

@override
bool operator ==(Object other) =>
    identical(this, other) ||
    other is ${fileName.pascalCase} &&
        runtimeType == other.runtimeType &&
        ${variables.names.map((e) => "$e == other.$e").join(" &&\n\t\t  ")};

${options.jsonToList ? '''static List<${fileName.pascalCase}> jsonToList(List list) =>
  list.map((e) => ${fileName.pascalCase}.fromJson(e as Map<String, dynamic>))
  .toList();
''' : ""}
}
'''));
  }
}