enhanceCreatorParams method

  1. @override
Future<void> enhanceCreatorParams(
  1. {required BuildContext context,
  2. required WidgetRef ref,
  3. required AppModel appModel,
  4. required CreatorModel creatorModel,
  5. 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 {
  ImageExportField imageField = field as ImageExportField;
  XFile? pickedFile =
      await ImagePicker().pickImage(source: ImageSource.gallery);

  if (pickedFile == null) {
    return;
  }

  Directory appDirDoc = await getApplicationSupportDirectory();
  String pickImagePath = '${appDirDoc.path}/imagePicker';
  Directory pickImageDir = Directory(pickImagePath);
  if (pickImageDir.existsSync()) {
    pickImageDir.deleteSync(recursive: true);
  }
  pickImageDir.createSync(recursive: true);

  String timestamp = DateFormat('yyyyMMddTkkmmss').format(DateTime.now());
  Directory imageDir = Directory('$pickImagePath/$timestamp');
  String imagePath = '${imageDir.path}/image';
  imageDir.createSync(recursive: true);

  await pickedFile.saveTo(imagePath);
  File pickedImage = File(imagePath);

  await imageField.setImages(
    cause: cause,
    appModel: appModel,
    creatorModel: creatorModel,
    newAutoCannotOverride: false,
    generateImages: () async {
      List<NetworkToFileImage> images = [
        NetworkToFileImage(file: pickedImage),
      ];

      return images;
    },
  );
}