在Flutter中,如何在原生文件资源管理器中为用户打开一个文件夹,以便用户可以浏览其文件/文件夹

问题描述 投票:0回答:1

我正在 flutter 中构建一个文件储物柜应用程序,它可以锁定文件和文件夹。当用户解锁文件夹时,我希望我的应用程序显示一个在本机文件资源管理器中查看文件夹内容的选项。有什么办法可以实现这个功能吗?

(提前感谢..)

android file flutter dart directory
1个回答
3
投票

您可以针对您提到的用例尝试此包:open_file

用途:

import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';

//Get the path to the directory
final String dir = (await getTemporaryDirectory()).path;

//Use the path to launch the directory with the native file explorer
await OpenFile.open('$dir\\');

注: 仅在 Windows 操作系统上测试)


如果您想在 Android 上进行测试,请使用另一个目录,例如

getExternalStorageDirectory
,因为
getTemporaryDirectory
在您的应用程序沙箱之外无法访问。

© www.soinside.com 2019 - 2024. All rights reserved.