resetProfileFields method

Future<void> resetProfileFields(
  1. AnkiMapping mapping
)

Resets a profile's fields such that it will have the model's number of fields, all empty.

Implementation

Future<void> resetProfileFields(AnkiMapping mapping) async {
  List<String> fields = await getFieldList(mapping.model);
  List<String?> exportFieldKeys =
      List.generate(fields.length, (index) => null);

  AnkiMapping resetMapping =
      mapping.copyWith(exportFieldKeys: exportFieldKeys);
  _database.writeTxnSync(() {
    if (mapping.id != null &&
        _database.ankiMappings.getSync(resetMapping.id!) != null) {
      _database.ankiMappings.deleteSync(resetMapping.id!);
    }
    _database.ankiMappings.putSync(resetMapping);
  });
}