lastSelectedMapping property

AnkiMapping lastSelectedMapping

Get the last selected mapping from persisted preferences. This should always be guaranteed to have a result, as it is impossible to delete the default mapping.

Implementation

AnkiMapping get lastSelectedMapping {
  String mappingName = _preferences.get(
    'last_selected_mapping',
    defaultValue: mappings.first.label,
  );

  AnkiMapping mapping = _database.ankiMappings
          .where()
          .labelEqualTo(mappingName)
          .findFirstSync() ??
      _database.ankiMappings
          .where()
          .labelEqualTo(mappings.first.label)
          .findFirstSync()!;

  return mapping;
}