setAudio method
- {required AppModel appModel,
- required CreatorModel creatorModel,
- required Future<
File?> generateAudio( - required bool newAutoCannotOverride,
- required EnhancementTriggerCause cause,
- String? searchTerm}
Perform a function that generates a list of images and attempt a search with a given search term.
Implementation
Future<void> setAudio({
required AppModel appModel,
required CreatorModel creatorModel,
required Future<File?> Function() generateAudio,
required bool newAutoCannotOverride,
required EnhancementTriggerCause cause,
String? searchTerm,
}) async {
if (_autoCannotOverride && cause == EnhancementTriggerCause.auto) {
return;
}
if (creatorModel.scrollController.hasClients &&
cause == EnhancementTriggerCause.manual) {
creatorModel.scrollController
.jumpTo(creatorModel.scrollController.position.minScrollExtent);
}
/// Show loading state.
setSearching(
appModel: appModel,
creatorModel: creatorModel,
isSearching: true,
searchTerm: searchTerm);
try {
File? file = await generateAudio();
if (file != null) {
setAudioFile(
appModel: appModel,
creatorModel: creatorModel,
file: file,
searchTermUsed: searchTerm,
);
} else {
if (cause == EnhancementTriggerCause.manual) {
Fluttertoast.showToast(
msg: t.audio_unavailable,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
}
}
_autoCannotOverride = newAutoCannotOverride;
} finally {
/// Finish loading state.
setSearching(
appModel: appModel,
creatorModel: creatorModel,
isSearching: false,
searchTerm: searchTerm,
);
}
}