onCreatorOpenAction method
- {required BuildContext context,
- required WidgetRef ref,
- required AppModel appModel,
- required CreatorModel creatorModel,
- required DictionaryHeading heading,
- required bool creatorJustLaunched,
- required String? dictionaryName}
override
Return the value that this field must have upon opening the Card Creator. For example, the Sentence field must provide the current context or the sentence that is stored in the app state, while the Image field may be used to return a snapshot of the current app context.
Implementation
@override
String? onCreatorOpenAction({
required BuildContext context,
required WidgetRef ref,
required AppModel appModel,
required CreatorModel creatorModel,
required DictionaryHeading heading,
required bool creatorJustLaunched,
required String? dictionaryName,
}) {
List<Dictionary> dictionaries = appModel.dictionaries;
Map<String, bool> dictionaryNamesByHidden = Map<String, bool>.fromEntries(
dictionaries
.map((e) => MapEntry(e.name, e.isHidden(appModel.targetLanguage))));
Map<String, int> dictionaryNamesByOrder = Map<String, int>.fromEntries(
dictionaries.map((e) => MapEntry(e.name, e.order)));
List<DictionaryEntry> hiddenEntries = heading.entries
.where(
(entry) => dictionaryNamesByHidden[entry.dictionary.value!.name]!)
.toList();
hiddenEntries.sort((a, b) =>
dictionaryNamesByOrder[a.dictionary.value!.name]!
.compareTo(dictionaryNamesByOrder[b.dictionary.value!.name]!));
return MeaningField.flattenMeanings(
entries: hiddenEntries,
prependDictionaryNames:
appModel.lastSelectedMapping.prependDictionaryNames ?? false);
}