Flutter Desktop - flutter-desktop-embedding how to save file to a hard drive

我怕爱的太早我们不能终老 提交于 2021-01-27 19:11:56

问题


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 :)

EDIT

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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/57741142/flutter-desktop-flutter-desktop-embedding-how-to-save-file-to-a-hard-drive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!