Sadikul Haque Sadi
Sadikul Haque Sadi

Reputation: 599

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. 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?

Upvotes: 2

Views: 7478

Answers (1)

user18309290
user18309290

Reputation: 8370

assets is read-only. 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.

Upvotes: 6

Related Questions