setAudio method

Future<void> setAudio(
  1. {required AppModel appModel,
  2. required CreatorModel creatorModel,
  3. required Future<File?> generateAudio(
      ),
    1. required bool newAutoCannotOverride,
    2. required EnhancementTriggerCause cause,
    3. 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,
        );
      }
    }