getCardFields static method

List<String> getCardFields(
  1. {required CreatorFieldValues creatorFieldValues,
  2. required AnkiMapping mapping,
  3. required Map<Field, String> exportedImages,
  4. required Map<Field, String> exportedAudio}
)

Returns the list that will be passed to the Anki card creation API to fill a card's fields. The contents of the list will correspond to the order of the mapping provided, with each field in the list replaced with the corresponding creatorFieldValues or in the case of the image and audio fields, the file names.

Implementation

static List<String> getCardFields({
  required CreatorFieldValues creatorFieldValues,
  required AnkiMapping mapping,
  required Map<Field, String> exportedImages,
  required Map<Field, String> exportedAudio,
}) {
  List<String> fields = mapping.getExportFields().map<String>((field) {
    if (field == null) {
      return '';
    } else {
      if (field is ImageExportField) {
        if (exportedImages[field] == null) {
          return '';
        } else {
          String text = exportedImages[field]!;
          if (mapping.exportMediaTags ?? false) {
            return '<img src="$text">';
          } else {
            return text;
          }
        }
      } else if (field is AudioExportField) {
        if (exportedAudio[field] == null) {
          return '';
        } else {
          String text = exportedAudio[field]!;
          if (mapping.exportMediaTags ?? false) {
            return '[sound:$text]';
          } else {
            return text;
          }
        }
      } else {
        String text = creatorFieldValues.textValues[field] ?? '';
        if (mapping.useBrTags ?? false) {
          text = text.replaceAll('\n', '<br>');
        }

        return text;
      }
    }
  }).toList();

  return fields;
}