有没有办法调用本地文件浏览器并获取所选目录的路径?
List<FileSystemEntity> _fileList;
Future<void> _loadFiles() async {
_loadingFiles = true;
var root = await getExternalStorageDirectory();
_fileList = await FileManager(root: root).walk().toList();
_loadingFiles = false;
this.setState(() {});
}
一旦您拥有了 _fileList 对象,您基本上可以随心所欲地进行操作。例如,我在我的 AppBar 中添加了一个 PopupMenuButton,并在其中允许文件删除、打开等操作。
对于 _fileList 列表中的每个项目,您还可以在 ListTile 中显示文件名、大小、修改日期等信息。
import 'package:filesystem_picker/filesystem_picker.dart';
import 'dart:io';
import 'package:path_provider/path_provider.dart';
Directory rootPath = await getTemporaryDirectory();
String? path = await FilesystemPicker.open(title: 'Save to folder',
context: context,
rootDirectory: rootPath,
fsType: FilesystemType.folder,
pickText: 'Save file to this folder',
folderIconColor: Colors.teal,
);
在 Kotlin/Java 中编写一个方法,并通过 MethodChannels 从 Flutter 中调用它。 如下启动本地文件管理器...
startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));
请参考下面的链接了解关于MethodChannels的许多内容
_getSDCardDirectory() async {
Directory directory = await getExternalStorageDirectory();
print(directory.path);
await directory.list().toList().then((filesList) => print(filesList));
print(directory.parent.path);
}