toWidgetDjFileDj method

FileDj? toWidgetDjFileDj(
  1. Map<String, String> djNamesMap
)

Implementation

FileDj? toWidgetDjFileDj(Map<String, String> djNamesMap) {
  var widgetFileName = ReCase(widgetDjName).snakeCase;

  var fields = parameters
      .map(
        (p) => FieldDj(
          name: p.name,
          dataType: p.type,
          safeDataType: _getFieldSafeDataType(p, djNamesMap).dataType,
          safetyDescription: _getFieldSafeDataType(p, djNamesMap).description,
          isFinal: p.isFinal,
          isRequired: p.isFieldRequired,
          isOptional: p.isOptional,
          defaultValue: p.defaultValue,
        ),
      )
      .toList();

  fields.add(
    FieldDj(
      name: 'baseWidgetDjType',
      dataType: 'String',
      defaultValue: "'$name'",
      superOnly: true,
    ),
  );

  var codeParts = <CodePartDj>[
    ImportDj(importStr: 'dj', isPackage: true),
    ImportDj(importStr: 'json_annotation', isPackage: true),
    EmptyLineDj(),
    ImportDj(importStr: widgetFileName, isPart: true),
    EmptyLineDj(),
    ClassDj(
      name: widgetDjName,
      isExtends: true,
      baseName: 'BaseWidgetDj',
      fields: fields,
      jsonSerializable: true,
      functions: [
        getToCode(fields),
        getToString(),
      ],
    ),
    EmptyLineDj(),
  ];

  // since we are setting all types to dynamic, we don't have to import
  // codeParts += _fieldImportDjs(fields, djNamesMap);

  var widgetDjCodeFileDj = FileDj(
    name: widgetFileName,
    codeParts: codeParts,
  );

  return widgetDjCodeFileDj;
}