saveToDownloads method

  1. @override
Future<String> saveToDownloads(
  1. String path,
  2. String? fileName
)
override

Implementation

@override
Future<String> saveToDownloads(String path, String? fileName) async {
  try {
    final home =
        Platform.environment['HOME'] ??
        Platform.environment['USERPROFILE'] ??
        Directory.systemTemp.path;
    final downloads = Directory('$home${Platform.pathSeparator}Downloads');
    if (!await downloads.exists()) {
      await downloads.create(recursive: true);
    }
    final name = fileName ?? path.split(RegExp(r'[/\\]')).last;
    final dest = File('${downloads.path}${Platform.pathSeparator}$name');
    if (await dest.exists()) await dest.delete();
    await File(path).copy(dest.path);
    return dest.path;
  } catch (e) {
    throw VideoCompressException(CompressErrorCode.saveFailed, '$e');
  }
}