[英]How can I save a local file into assets folder in Flutter
My flutter desktop application takes a local file (audio/video/image) as user input.我的颤振桌面应用程序将本地文件(音频/视频/图像)作为用户输入。 Now I need to save it to somewhere for later usage.
现在我需要将它保存到某个地方以备后用。 So that even if the device changes the application can still access them using relative path.
这样即使设备发生变化,应用程序仍然可以使用相对路径访问它们。
What I want to do is copy this file to assets folder using file.copy
method.我想要做的是使用
file.copy
方法将此文件复制到assets文件夹。 But how can I get the assets folder's directory?但是我怎样才能得到资产文件夹的目录呢? I don't want to hardcode assets folder's absolute path.
我不想硬编码资产文件夹的绝对路径。 Is there any way to copy files into assets folder using relative path?
有没有办法使用相对路径将文件复制到资产文件夹中?
Or any alternate way to do the task?或者任何替代方法来完成任务?
assets
is read-only. assets
是只读的。 Use documents directory where the application can store files that only it can access.使用应用程序可以存储只有它可以访问的文件的文档目录。
final directory = await getApplicationDocumentsDirectory();
See Read and write files for details.有关详细信息,请参阅读取和写入文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.