executeAction method

  1. @override
Future<void> executeAction(
  1. {required BuildContext context,
  2. required WidgetRef ref,
  3. required AppModel appModel,
  4. required CreatorModel creatorModel,
  5. required DictionaryHeading heading,
  6. required String? dictionaryName}
)
override

Execute the functionality of this action.

Implementation

@override
Future<void> executeAction({
  required BuildContext context,
  required WidgetRef ref,
  required AppModel appModel,
  required CreatorModel creatorModel,
  required DictionaryHeading heading,
  required String? dictionaryName,
}) async {
  if (appModel.isCreatorOpen) {
    Map<Field, String> newTextFields = {};
    for (Field field in appModel.activeFields) {
      String? newTextField = field.onCreatorOpenAction(
        context: context,
        ref: ref,
        appModel: appModel,
        creatorModel: creatorModel,
        heading: heading,
        creatorJustLaunched: false,
        dictionaryName: dictionaryName,
      );

      if (newTextField != null) {
        newTextFields[field] = newTextField;
      }
    }

    creatorModel.copyContext(
      CreatorFieldValues(textValues: newTextFields),
    );

    for (Field field in appModel.activeFields) {
      Enhancement? enhancement = appModel.lastSelectedMapping
          .getAutoFieldEnhancement(appModel: appModel, field: field);

      if (enhancement != null) {
        enhancement.enhanceCreatorParams(
          context: context,
          ref: ref,
          appModel: appModel,
          creatorModel: creatorModel,
          cause: EnhancementTriggerCause.auto,
        );
      }
    }

    appModel.notifyRecursiveSearch();

    Navigator.of(context).popUntil((route) {
      return route.settings.name == (CreatorPage).toString();
    });
  } else {
    if (appModel.isMediaOpen && appModel.shouldHideStatusBarWhenInMedia) {
      await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
      await Future.delayed(const Duration(milliseconds: 5), () {});
    }

    Map<Field, String> newTextFields = {};
    for (Field field in appModel.activeFields) {
      String? newTextField = field.onCreatorOpenAction(
        context: context,
        ref: ref,
        appModel: appModel,
        creatorModel: creatorModel,
        heading: heading,
        creatorJustLaunched: true,
        dictionaryName: dictionaryName,
      );

      if (newTextField != null) {
        newTextFields[field] = newTextField;
      }
    }

    await appModel.openCreator(
      ref: ref,
      killOnPop: false,
      creatorFieldValues: CreatorFieldValues(textValues: newTextFields),
    );

    if (appModel.isMediaOpen && appModel.shouldHideStatusBarWhenInMedia) {
      await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
    }
  }
}