populateEnhancements method

void populateEnhancements()

Populate maps for enhancements at startup to optimise performance.

Implementation

void populateEnhancements() async {
  /// A list of enhancements that the app will support at runtime.
  final Map<Field, List<Enhancement>> availableEnhancements = {
    AudioField.instance: [
      ClearFieldEnhancement(field: AudioField.instance),
      JapanesePod101AudioEnhancement(),
      ForvoAudioEnhancement(),
      PickAudioEnhancement(field: AudioField.instance),
      AudioRecorderEnhancement(field: AudioField.instance),
    ],
    AudioSentenceField.instance: [
      ClearFieldEnhancement(field: AudioSentenceField.instance),
      PickAudioEnhancement(field: AudioSentenceField.instance),
      AudioRecorderEnhancement(field: AudioSentenceField.instance),
    ],
    NotesField.instance: [
      ClearFieldEnhancement(field: NotesField.instance),
      OpenStashEnhancement(field: NotesField.instance),
      PopFromStashEnhancement(field: NotesField.instance),
    ],
    ImageField.instance: [
      ClearFieldEnhancement(field: ImageField.instance),
      BingImagesSearchEnhancement(),
      CropImageEnhancement(),
      PickImageEnhancement(),
      CameraEnhancement(),
    ],
    MeaningField.instance: [
      ClearFieldEnhancement(field: MeaningField.instance),
      SentencePickerEnhancement(field: MeaningField.instance),
    ],
    ReadingField.instance: [
      ClearFieldEnhancement(field: ReadingField.instance),
    ],
    SentenceField.instance: [
      ClearFieldEnhancement(field: SentenceField.instance),
      TextSegmentationEnhancement(),
      SentencePickerEnhancement(field: SentenceField.instance),
      OpenStashEnhancement(field: SentenceField.instance),
      PopFromStashEnhancement(field: SentenceField.instance),
    ],
    TermField.instance: [
      ClearFieldEnhancement(field: TermField.instance),
      SearchDictionaryEnhancement(),
      MassifExampleSentencesEnhancement(),
      TatoebaExampleSentencesEnhancement(),
      ImmersionKitEnhancement(),
      OpenStashEnhancement(field: TermField.instance),
      PopFromStashEnhancement(field: TermField.instance),
    ],
    ContextField.instance: [
      ClearFieldEnhancement(field: ContextField.instance),
      OpenStashEnhancement(field: ContextField.instance),
      PopFromStashEnhancement(field: ContextField.instance),
    ],
    PitchAccentField.instance: [
      ClearFieldEnhancement(field: PitchAccentField.instance),
    ],
    FuriganaField.instance: [
      ClearFieldEnhancement(field: FuriganaField.instance),
    ],
    FrequencyField.instance: [
      ClearFieldEnhancement(field: FrequencyField.instance),
    ],
    CollapsedMeaningField.instance: [
      ClearFieldEnhancement(field: CollapsedMeaningField.instance),
      SentencePickerEnhancement(field: CollapsedMeaningField.instance),
    ],
    ExpandedMeaningField.instance: [
      ClearFieldEnhancement(field: ExpandedMeaningField.instance),
      SentencePickerEnhancement(field: ExpandedMeaningField.instance),
    ],
    HiddenMeaningField.instance: [
      ClearFieldEnhancement(field: HiddenMeaningField.instance),
      SentencePickerEnhancement(field: HiddenMeaningField.instance),
    ],
    TagsField.instance: [
      ClearFieldEnhancement(field: TagsField.instance),
      SaveTagsEnhancement(),
    ],
    ClozeBeforeField.instance: [
      ClearFieldEnhancement(field: ClozeBeforeField.instance),
    ],
    ClozeAfterField.instance: [
      ClearFieldEnhancement(field: ClozeAfterField.instance),
    ],
    ClozeInsideField.instance: [
      ClearFieldEnhancement(field: ClozeInsideField.instance),
    ],
  };

  enhancements = Map<Field, Map<String, Enhancement>>.unmodifiable(
    availableEnhancements.map(
      (field, enhancements) => MapEntry(
        field,
        Map<String, Enhancement>.unmodifiable(
          Map<String, Enhancement>.fromEntries(
            enhancements.map(
              (enhancement) => MapEntry(enhancement.uniqueKey, enhancement),
            ),
          ),
        ),
      ),
    ),
  );
}