Flutter:应用程序在加密时卡住

Flutter: Application stucks while is encrypting

我在加密和解密我的视频文件以及加密视频文件时遇到问题。没有任何错误。但它在加密和解密视频文件时卡住了。我使用异步方法。但它仍然卡住。我的代码如下。

加密:

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;
    }
  }

解密:

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;
    }
  }

谢谢。

为了避免卡顿,您需要在后台执行这样昂贵的计算。在 Android,这意味着在不同的线程上安排工作。在 Flutter 中,可以使用单独的 Isolate and Compute。你可能需要这样的东西:

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;
    }
  }

其他网友来这里,相同主题的答案在这里