简体   繁体   English

如何将本地文件保存到 Flutter 的 assets 文件夹中

[英]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.

相关问题 Flutter 将APK文件保存在assets文件夹中以进行下载 - Flutter Save APK file in assets folder to download 如何将资产文件夹中的图像添加到本地 HTML 文件并在 Flutter Z3E7D16622A52391BD7BF68CAE 中显示 HTML 文件 - How to add an image from assets folder to local HTML file and display the HTML file in Flutter WebView 如何从存储在资产中的本地文件夹添加 flutter 图像 - How to add flutter image from local folder stored in assets 如何将在 Flutter 上查看的 pdf 文件保存到设备的本地存储? - How can I save viewing pdf file on Flutter to Local Storage of the device? 我可以将 flutter 资产用于 iOS 上的本地通知附件吗 - Can I use flutter assets for local notification attachments on iOS 如何在颤振应用程序的资产文件夹中写入和读取文件? - How to write to and read from a file in my assets folder in a flutter app? 如何在颤动中将文件保存在下载文件夹中? - How to save File in Downloads folder in flutter? 如何使用flutter for web从本地文件中读取内容? - How can I read content form a local file with flutter for web? Flutter better_player:如何从本地资产文件夹播放视频 - Flutter better_player: How to play video from local assets folder 我无法从 Flutter 中的资产文件添加图像 - I can't add the image from assets file in Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM