1

I have a problem encrypting and decrypting my video file and it encrypting video file. there is no any error. but it stucks while is encrypting and decrypting video files. I use asynchronous method. but it still stucks. my code below.

encrypt:

Future sifrele() async {
    try {
      crypt.setOverwriteMode(AesCryptOwMode.on);
      encFilepath = await crypt.encryptFile(realPath + '/WhatCarCanYouGetForAGrand.mp4', realPath + '/video.mp4.aes');
      print('The encryption has been completed successfully.');
    } on AesCryptException catch (e) {
      if (e.type == AesCryptExceptionType.destFileExists) {
        print('The encryption has been completed unsuccessfully.');
      }
      return;
    }
  }

decrypt:

Future decrypting() async {
    var videos = File(realPath + "/ElephantsDream.mp4.aes");
    try {
      realPath = await crypt.decryptFile(realPath + '/video.mp4.aes', realPath + '/cozulen.mp4');
      print('The decryption has been completed successfully.');
    } on AesCryptException catch (e) {
      if (e.type == AesCryptExceptionType.destFileExists) {
        print('The decryption has been completed unsuccessfully.');
      }
      return;
    }
  }

thanks.

FesaTR
  • 47
  • 6

2 Answers2

1

To avoid jank, you need to perform expensive computations like this in the background. On Android, this means scheduling work on a different thread. In Flutter, you can use a separate Isolate and Compute. you should probably need something like this:

void _Startdecrypting(){
   compute(decrypting, /** If you need any input for your method put them here **/);
}



decrypting() {
    var videos = File(realPath + "/ElephantsDream.mp4.aes");
    try {
      realPath = crypt.decryptFile(realPath + '/video.mp4.aes', realPath + '/cozulen.mp4');
      print('The decryption has been completed successfully.');
    } on AesCryptException catch (e) {
      if (e.type == AesCryptExceptionType.destFileExists) {
        print('The decryption has been completed unsuccessfully.');
      }
      return;
    }
  }
Payam Asefi
  • 2,677
  • 2
  • 15
  • 26
1

For the other users come here, the answer on the same topic is here Flutter: run multiple methods

EmadFathy
  • 158
  • 1
  • 9
  • it works. thanks. but everyone have to read comment. because I add "static" to head of function. – FesaTR Oct 20 '20 at 12:10