如何从 Flutter 应用程序启动系统文件管理器?

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

我想从我的 flutter 中启动默认的文件管理器。我不想为我的应用程序选择文件。我只是想启动它(最好显示我希望它显示的目录),以便用户可以从该目录中选择一个文件并用它做任何他们想做的事情。

有人可以告诉我该怎么做吗?我看到很多用于选择文件的代码和示例,但这不是我需要的。只是想启动默认的文件管理器。

请不要推荐FilePicker。那不是我要找的。我不想“选择”一个文件。我知道如何选择文件。我只想启动默认的文件管理器应用程序。我不希望无论用户是否选择文件,控件都返回到应用程序。

flutter
2个回答
0
投票

这也让我感到悲伤。这是我的解决方案。

使用“external_app_launcher”,您可以根据应用程序的 URL 方案启动应用程序,因此我们...

import 'package:external_app_launcher/external_app_launcher.dart';

okButton = TextButton(
  child: const Text("Open Files"),
  onPressed: () async {
    await LaunchApp.openApp(iosUrlScheme: 'shareddocuments://', openStore: false);
  },
);

这将启动该应用程序,我仍在研究我的解决方案,因为我想打开我的应用程序文件夹,因此会随着我获得更多信息而更新。

编辑: 因此,要在我的应用程序文件夹中打开此文件(在 IOS 上)

final directory = await getApplicationDocumentsDirectory();
String dir = directory.path;
okButton = TextButton(
    child: const Text("Open Files"),
    onPressed: () async {
      await LaunchApp.openApp(
        iosUrlScheme: 'shareddocuments://$dir',
        openStore: false,
      );
    },
);

-2
投票

您可以使用 file_picker 包。

使用方法

    FilePickerResult? result = await FilePicker.platform.pickFiles();
    
    if (result != null) {
      File file = File(result.files.single.path);
    } else {
      // User canceled the picker
    }

编辑:现在我明白你想要什么了。检查https://pub.dev/packages/external_app_launcher

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