process method

  1. @override
Future<FileWrapper> process(
  1. FilePickerConfig config,
  2. FileWrapper file
)
override

method that is to be implemented.

Implementation

@override
Future<FileWrapper> process(FilePickerConfig config, FileWrapper file) async {
  if (kIsWeb) return file;

  if (file.isImage() && file.content != null) {
    final File originalFile = File(file.xFilePath);
    ImageEditor.i18n(ComponentStrings.of(buildContext.call()).getAll());
    final bytes = await Navigator.of(buildContext.call(), rootNavigator: true).push<Uint8List>(
      ZdsFadePageRouteBuilder(
        fullscreenDialog: true,
        builder: (context) {
          return ImageEditor(
            image: originalFile.readAsBytesSync(),
            emojiOption: null,
            textOption: null,
            blurOption: null,
          );
        },
      ),
    );

    if (bytes != null) {
      final String dir = await zdsTempDirectory('edited');
      await originalFile.delete(recursive: true);
      final File result = File(path.join(dir, path.basename(originalFile.absolute.path)));
      await result.writeAsBytes(bytes);
      return FileWrapper(file.type, ZdsXFile.fromFile(result));
    }
  }

  return file;
}