Flutter 颤振:应用程序在加密时阻塞

Flutter 颤振:应用程序在加密时阻塞,flutter,encryption,crypt,Flutter,Encryption,Crypt,我在加密和解密我的视频文件以及它加密视频文件时遇到问题。没有任何错误。但它在加密和解密视频文件时会出现问题。我使用异步方法。但它仍然很糟糕。下面是我的代码 加密: Future sifrele() async { try { crypt.setOverwriteMode(AesCryptOwMode.on); encFilepath = await crypt.encryptFile(realPath + '/WhatCarCanYouGetForAGrand.m

我在加密和解密我的视频文件以及它加密视频文件时遇到问题。没有任何错误。但它在加密和解密视频文件时会出现问题。我使用异步方法。但它仍然很糟糕。下面是我的代码

加密:

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

谢谢。

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

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

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

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

对于其他用户,相同主题的答案在这里

对于其他用户,相同主题的答案在这里

我尝试隔离。但是我不知道我该怎么做。你能给我举个例子吗?@fesater看看我的英语不完美。如果你有一个例子,你能写在这里吗?@fesater不幸的是,我也没有太多的经验。我试着孤立。但是我不知道我该怎么做。你能给我举个例子吗?@fesater看看我的英语不完美。如果你有一个例子,你能写在这里吗?@FesaTR不幸的是,我对它也没有太多经验。它很有效。谢谢但每个人都必须阅读评论。因为我在函数的开头添加了“static”,它是有效的。谢谢但每个人都必须阅读评论。因为我在函数的开头添加了“static”。