enhanceCreatorParams method
- {required BuildContext context,
- required WidgetRef ref,
- required AppModel appModel,
- required CreatorModel creatorModel,
- required EnhancementTriggerCause cause}
override
Perform a change to the CreatorModel, executing the functionality of this enhancement. An EnhancementTriggerCause may be used to modify the behavior of the enhancement's function depending on whether the enhancement is being executed on auto, manual or cascade modes.
Implementation
@override
Future<void> enhanceCreatorParams({
required BuildContext context,
required WidgetRef ref,
required AppModel appModel,
required CreatorModel creatorModel,
required EnhancementTriggerCause cause,
}) async {
String searchTerm = creatorModel.getFieldController(field).text;
List<String> exampleSentences = await searchForSentences(
context: context,
appModel: appModel,
searchTerm: searchTerm,
);
appModel.openExampleSentenceDialog(
exampleSentences: exampleSentences,
onSelect: (selection) {
if (selection.isEmpty) {
return;
}
String firstResult = selection.removeAt(0);
creatorModel
.setSentenceAndCloze(JidoujishoTextSelection(text: firstResult));
creatorModel.getFieldController(ContextField.instance).clear();
for (String result in selection) {
creatorModel.appendSentenceAndCloze(result);
}
},
onAppend: (selection) {
if (selection.isEmpty) {
return;
}
String currentSentence =
creatorModel.getFieldController(SentenceField.instance).text;
creatorModel.getFieldController(SentenceField.instance).text =
'${currentSentence.trim()}\n\n${selection.join('\n\n')}'.trim();
},
);
}