【问题标题】:Flutter: Application stucks while is encryptingFlutter:应用程序在加密时卡住
【发布时间】:2020-10-15 13:45:10
【问题描述】:

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

加密:

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

谢谢。

【问题讨论】:

    标签: flutter encryption crypt


    【解决方案1】:

    对于其他用户来这里,相同主题的答案在这里Flutter: run multiple methods

    【讨论】:

    • 它有效。谢谢。但每个人都必须阅读评论。因为我在函数头中添加了“静态”。
    【解决方案2】:

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

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

    【讨论】:

    • 我尝试隔离。但我不知道我该怎么做。你能给我举个例子吗?
    • @FesaTR 看看this link
    • 我的英语不完美。如果你有例子,你可以在这里写吗?
    • @FesaTR 不幸的是我也没有太多经验。
    猜你喜欢
    • 2019-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多