Flutter: run multiple methods


I have a big problem. If I want to encrypt my video file, my application is freezing until that method finishing. But there is no error. How can I code my application does not freeze. thanks.

Future sifrele() async {
  String realPath =

    var crypt = AesCrypt('sefa');
    try {
      String encFilepaths = await crypt.encryptFile(
          realPath + '/WhatCarCanYouGetForAGrand.mp4',
          realPath + '/video.mp4.aes');
      print('The encryption has been completed successfully.');
      //print('Encrypted file: $encFilepath');

    } on AesCryptException catch (e) {
      if (e.type == AesCryptExceptionType.destFileExists) {
        print('The encryption has been completed unsuccessfully.');


Change the function type of your function from Future to FutureOr, add a parameter to the function (even if you don’t need it)
and use compute. it will work perfectly.


Future sifrele() async {


FutureOr sifrele(String para) async {


  doTheEncryption() {
    compute(sifrele, 'Pass the value of the parameter here if you need it');

Another one important thing the definition of the function sifrele must be a top level, meaning not inside the class, put it outside the class.
The function doTheEncryption() (or whaterver you name it) maybe inside the class no problem.

Answered By – EmadFathy

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *