extractToDirectory static method Null safety

Future<void> extractToDirectory(
  1. {required File zipFile,
  2. required Directory destinationDir,
  3. OnExtracting? onExtracting,
  4. String? zipFileCharset}

Extract zipFile to a given destinationDir. Optional callback function onExtracting is called before extracting a zip entry.

onExtracting must return one of the following values: ZipFileOperation.includeItem - extract this file/directory ZipFileOperation.skipItem - do not extract this file/directory ZipFileOperation.cancel - cancel the operation

In iOS and Android (API level >= 24) you can also specify the charset zipFileCharset to be used to decode the ZIP entry names and comments. The enum Charsets defines the most common values (use e.g. Charsets.UTF_8.name). More information: https://developer.android.com/reference/java/util/zip/ZipFile#ZipFile(java.lang.String,%20java.nio.charset.Charset)


static Future<void> extractToDirectory({
  required File zipFile,
  required Directory destinationDir,
  OnExtracting? onExtracting,
  String? zipFileCharset,
}) async {
  final reportProgress = onExtracting != null;
  if (reportProgress) {
    if (!_isMethodCallHandlerSet) {
      _isMethodCallHandlerSet = true;
  final jobId = ++_jobId;
  try {
    if (onExtracting != null) {
      _onExtractingHandlerByJobId[jobId] = onExtracting;

    await _channel.invokeMethod<void>('unzip', <String, dynamic>{
      'zipFile': zipFile.path,
      'zipFileCharset': zipFileCharset,
      'destinationDir': destinationDir.path,
      'reportProgress': reportProgress,
      'jobId': jobId,
  } finally {