【问题标题】:How can i implement Flutter File Picker in Website我如何在网站中实现 Flutter 文件选择器
【发布时间】:2020-09-07 23:25:22
【问题描述】:

我们如何在 Flutter Web 开发中从本地系统驱动器中选择文件。不在应用程序中 请任何人建议我。

我是这样使用的 我可以选择文件 但是我怎样才能得到文件路径

【问题讨论】:

  • 请提供更多信息以提供帮助,并记住将带有错误日志的代码 sn-p 作为文本而不是屏幕截图发布。
  • 请检查这两个帖子。 post1post2。希望这能解决您的问题。
  • 这能回答你的问题吗? How to get the file selected

标签: flutter flutter-web


【解决方案1】:

您需要获取数据并为其创建一个 MediaInfo 类

class MediaInfo{
  String fileName;
  String filePath;
}

获取文件路径

Future<MediaInfo> convertFileGetNamePath({@required html.File file}) async {
  final Map<String, dynamic> infoData = {};
  final reader = html.FileReader();
  reader.readAsDataUrl(file);
  await reader.onLoad.first;
  final fileName = file.name;
  infoData.addAll({
    'name': fileName,
    'path': filePath,
  });

  MediaInfo webImageInfo = MediaInfo();
  webImageInfo.fileName = infoData['name'];
  webImageInfo.filePath = infoData['path'];
  return webImageInfo;

}

在你的代码中实现它

MediaInfo getInfo = await convertFileGetNamePath(file: imageFile);
fileName = getInfo.fileName;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    • 2020-09-18
    • 1970-01-01
    • 1970-01-01
    • 2018-03-16
    相关资源
    最近更新 更多