搜索插件、代码仓与 APP 分类

插件详情v1.2.0

downloadsfolder

一个用于在不同平台上获取下载文件夹路径并执行与文件下载相关操作的Flutter插件。

AndroidiOSmacOSWindows
近 30 天下载
1.8万
喜欢数
53
Pub 分数
150

安装插件

flutter pub add downloadsfolder

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

downloadsfolder 包是一个 Flutter 插件,提供对设备下载文件夹的跨平台访问。它使应用程序能够获取下载目录的路径,并在此位置执行文件操作,例如保存或读取文件。兼容 Android、iOS、macOS 和 Windows,通过抽象平台特定逻辑,简化了在不同操作系统上处理下载文件的操作。该插件非常适合需要可靠且一致地管理已下载文件的应用程序。

适合场景

  • 保存用户下载的文件
  • 程序化访问已下载的内容
  • 跨平台文件管理
  • 与下载管理器集成
  • 处理应用生成的下载

主要特点

  • 跨平台下载路径获取
  • 支持 Android、iOS、macOS 和 Windows
  • 文件操作的简单 API
  • 跨平台的一致行为
  • 轻量且易于集成

适合对象

  • 文件管理应用
  • 媒体或文档查看器
  • 下载工具
  • 需要持久化存储的应用程序
  • 面向多平台的开发者

使用建议

  • 某些平台可能需要权限
  • iOS 需要在 Info.plist 中进行正确的配置
  • 行为在不同操作系统版本之间可能略有差异
  • 不适用于大规模文件系统操作
  • 限于下载文件夹范围

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Download Folder Plugin

A Flutter plugin for retrieving the path to the downloads folder and performing operations related to file downloads on different platforms.

Support

Android iOS Windows macOS Linux
Support SDK 19+ iOS 12+ ✅ ✅ ✅

How it works?

The Flutter Download Folder plugin provides a simple interface to interact with the downloads folder on various platforms. Here's a brief overview of how the main functionalities work:

Get Download Directory

getDownloadDirectory() returns a Directory pointing at the platform's downloads location. On Android this is Environment.DIRECTORY_DOWNLOADS; on iOS it is the app's documents directory; on the desktop platforms it is the OS-provided downloads folder.

Copy File into Download Folder

copyFileIntoDownloadFolder(...) copies a file into the downloads folder, ensuring a unique name to avoid overwriting existing files. Optional knobs:

  • subDirectoryPath — drop the file into a sub-folder of Downloads (e.g. "Reports"); missing intermediate directories are created automatically.
  • openAfterSave — when true, the saved file is opened in the OS default viewer immediately after the copy.

On Android 10+ (API 29+) the file is saved via MediaStore so the plugin does not require MANAGE_EXTERNAL_STORAGE. It returns a SavedDownload? exposing both the on-disk file and (on Android 10+ only) the MediaStore contentUri; see the scoped-storage note below. Returns null if the save failed.

Open Download Folder

openDownloadFolder() opens the download folder in the system file browser. On Android and iOS this goes through a platform channel; on Windows/macOS/Linux it shells out to the appropriate native command.

Installation

To use this plugin, add downloadsfolder as a dependency in your pubspec.yaml file:

dependencies:
  downloadsfolder: ^2.0.0-pre.2

Setup

Android
  • The copyFileIntoDownloadFolder method uses a workaround on Android 29 and higher to avoid using MANAGE_EXTERNAL_STORAGE.
    • On Android devices with API 29 and higher, the method saves the file using MediaStore to bypass restrictions.
    • On Android devices with API 28 and lower, ensure that you have added the WRITE_EXTERNAL_STORAGE permission to your AndroidManifest.xml file under the <application> element.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/>
iOS
  • To enable the openDownloadFolder function on iOS, you must add the UISupportsDocumentBrowser key to your Info.plist. Without it, iOS will refuse to resolve the shareddocuments:// URL the plugin opens and openDownloadFolder will return false.
<key>UISupportsDocumentBrowser</key>
<true/>
macOS

Go to your project folder, macOS/Runner/DebugProfile.entitlements

For release you need to open 'YOUR_PROJECT_NAME'Profile.entitlements

and add the following key:

<key>com.apple.security.files.downloads.read-write</key>
<true/>

Usage

Get Download Directory
import 'package:downloadsfolder/downloadsfolder.dart';

void main() async {
  try {
    final Directory downloadDirectory = await getDownloadDirectory();
    print('Downloads folder path: ${downloadDirectory.path}');
  } catch (e) {
    print('Failed to retrieve downloads folder path $e');
  }
}
Copy File into Download Folder
import 'package:downloadsfolder/downloadsfolder.dart';

void main() async {
  final String filePath = '/path/to/source/file.txt';
  final String fileName = 'copied_file.txt';

  final SavedDownload? saved = await copyFileIntoDownloadFolder(
    filePath,
    fileName,
    subDirectoryPath: 'Reports', // optional — saves under /Download/Reports
    openAfterSave: true,         // optional — pops the file in the OS default viewer
  );
  if (saved != null) {
    print('File saved at: ${saved.file.path}');
    if (saved.contentUri != null) {
      // Android 10+: use this URI for read/share/intent work.
      print('MediaStore URI: ${saved.contentUri}');
    }
  } else {
    print('Failed to copy file.');
  }
}

Android 10+ note (scoped storage). The SavedDownload.file path is real — the file genuinely lives at that location and any file-manager app can see it. However, due to Android's scoped storage rules, your own app generally cannot read or write that path back via plain dart:io once the save is complete. Use SavedDownload.contentUri for any subsequent work (sharing through share_plus, opening with an ACTION_VIEW intent, reading bytes via ContentResolver, etc.). On Android < 10, iOS, and the desktop platforms, file is directly usable with dart:io and contentUri is null.

Open Download Folder
import 'package:downloadsfolder/downloadsfolder.dart';

void main() async {
  final bool success = await openDownloadFolder();
  if (success) {
    print('Download folder opened successfully.');
  } else {
    print('Failed to open download folder.');
  }
}

所属分类

依赖

依赖清单 5 项

源码仓库

使用此插件的项目