Flutter Desktop-Flutter-Desktop-embedded如何将文件保存到硬盘 [英] Flutter Desktop - flutter-desktop-embedding how to save file to a hard drive

查看:411
本文介绍了Flutter Desktop-Flutter-Desktop-embedded如何将文件保存到硬盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Flutter桌面上工作了一段时间,实施进展顺利.到现在为止,我只实现UI,网络和内存缓存.现在,我开始面对一个无法解决的实际问题.是否有可能将文件保存到硬盘驱动器?我必须处理包含PDF文件的base64,并将其放在硬盘驱动器上的某个位置.我应该使用为移动设备准备的功能,还是在Flutter中为台式机准备的功能更加复杂,并且我必须为平台实现适当的功能并将其公开给Flutter?如果这有任何改变,我主要针对Windows生态系统.我想到的另一种解决方案是准备bash/power-shell脚本来为我执行此操作,但希望我不需要这样做:)

I am working with the Flutter desktop for a while and everything is going fine with the implementation. Till now I was only implementing the UI, networking and in-memory cache. Now I started to face a real problem that I am not able to to find the solution for. Is there a chance that there is some out of the box possibility to save files to a hard drive? I have got to process the base64 that contains a PDF file and put it somewhere on the hard drive. Should I use functions that are prepared for the mobile devices or this is something more complicated in Flutter for the desktop and I have to implement a proper function for the platform and expose it to the Flutter? I mainly target the Windows ecosystem if this changes anything. Only another solution that comes to my mind is to prepare the bash/power-shell script to do that for me, but hopefully, I would not need to do that :)

编辑

我在这里遇到的主要问题是我想检索用户文件夹的路径.有人知道怎么做吗?

The main problem that I encounter here is that I would like to retrieve the path to the user folder. Does anyone know how to do that?

推荐答案

最好的方法是使用平台渠道. flutter-desktop-embedding项目托管几种flutter/插件插件,虽然path_provider在那里不是当前的,但可以肯定地添加它(macOS实施已存在PR).然后,您可以像在移动设备上一样使用getApplicationDocumentsDirectory().

The best way to do it would be with a platform channel. The flutter-desktop-embedding project hosts desktop implementations of several flutter/plugins plugins, and while path_provider isn't current there, it could certainly be added (there's already a PR for a macOS implementation). Then you could use getApplicationDocumentsDirectory() just as you would on mobile.

或者,您可以查看是否有环境变量为您提供所需的数据,因为Dart已经可以访问它们,但是在操作系统版本/配置之间可能不那么可靠.

Alternately you could see if there are environment variables that give you the data you want, since they are already accessible to Dart, but that may not be as reliable across OS versions/configurations.

这篇关于Flutter Desktop-Flutter-Desktop-embedded如何将文件保存到硬盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆