kineapps / flutter_archive

Flutter plugin for creating and extracting ZIP files.
https://pub.dev/packages/flutter_archive
BSD 3-Clause "New" or "Revised" License
57 stars 43 forks source link

Problem with the new progress function in compress operation #34

Closed csacchetti closed 3 years ago

csacchetti commented 3 years ago

Hi, first of all thank you for having included the progress in the file compression operation as well. I ask for help, because I tried to implement it following the new instructions but I have a problem. Compression occurs regularly as before but progress does not. In the console nothing is printed and moreover if I leave the assert it also gives me this error.

Failed assertion: line 61 pos 12: '!progress || onProgressCallCount1 > 0': is not true.

0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)

1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)

If I delete the assert it doesn't give me any errors, the directory compresses, but the progress is not returned.

I am attaching my function to you so that you can tell me where the error possibly is. Thank you

Future<void> compressZipProgress(BuildContext context, Function myCallBack,
    String pathDirectoryToSave, String pathZipFile,
    {bool progress = false}) async {
  String _dirDoc = context.read<ProviderPref>().pathDocumentsProv;
  final Directory _directoryToSave =
      Directory(join(_dirDoc, pathDirectoryToSave));
  final _zipFilePath = join(_dirDoc, pathZipFile);

  final _zipFile = File(_zipFilePath);
  if (await _zipFile.exists()) await _zipFile.delete();
  int onProgressCallCount1 = 0;

  try {
    await ZipFile.createFromDirectory(
      sourceDir: _directoryToSave,
      zipFile: _zipFile,
      recurseSubDirs: true,
      includeBaseDirectory: false,
      onZipping: progress
          ? (fileName, isDirectory, progress) {
              ++onProgressCallCount1;
              print(onProgressCallCount1);
              print('Zip #1:');
              print('progress: ${progress.toStringAsFixed(1)}%');
              print('name: $fileName');
              print('isDirectory: $isDirectory');
              return ZipFileOperation.includeItem;
            }
          : null,
    );
    assert(!progress || onProgressCallCount1 > 0);
  } on PlatformException catch (e) {
    print(e);
  }
  myCallBack(context, pathZipFile);
}

The function that call this is:

compressZipProgress(context, openShareWindow, "myFile", "myFile.zip", progress: true);
kinex commented 3 years ago

Hi, how many files are you zipping? Android or iOS?

csacchetti commented 3 years ago

For the moment I have only tested on iOS. I have a basic directory with four directories inside which contain: 4, 1, 6, files. The last directory has various directories which contain 7 to 29 files.

kinex commented 3 years ago

I cannot reproduce this issue. Please try the example app, does it work in your test device? If you cannot find the issue, provide a full and minimal source code to reproduce the issue.