3
votes

I have Flutter app which needs to load dynamic assets and content which I want to save for later use. I know about Assets I can have in build time at the folder "assets/" inside the app.

I want to download content using ZIP files and unzip them to app local folder so they won't delete in the next app update.

what are the folders Flutter allows me to add assets to at runtime?

1
Did the official documentation suit your issue? Or you have external storage requirement? - Tokenyet
I read the official docs, but have some small questions about the storage and app updates. I want to cache assets for long use and wander if the Assets folder is also updatable without an install app update. - Nisim Joseph
I'm afraid It's not possible to do so, assets are statics, and I can't think of any use case to dynamic assets. I think you should provide the scenario of your works to make more sense. By the way, LocalStorage will not be removed in next app update, so I can't figure out why you focus on '/assets'. The only thing I guess is you want to make a app-cloner? If this is the case, I don't know anything about this :( - Tokenyet
I want to have dynamic Splash Screen (A/B test) so the assets are not in the app and will loaded from CDN. - Nisim Joseph

1 Answers

3
votes

You cannot dynamically add assets to Flutter app at runtime and that is why Shared_Preferences package was developed by the official Flutter_Dev Team.

https://pub.dev/packages/shared_preferences

If you want to store a File instead of bits of information then refer to the below example code (For a Image File):

Future getImage(ImageSource imageSource) async {
// using your method of getting an image
final File image = await ImagePicker.pickImage(source: imageSource);

// getting a directory path for saving
final String path = await getApplicationDocumentsDirectory().path;

// copy the file to a new path
final File newImage = await image.copy('$path/image1.png');

setState(() {
  _image = newImage;
});} 

If your still want to somehow add/delete files dynamically then the answer is that it is practically not possible because assets weren't designed to dynamically store files.

One should only use assets to store files which shall remain common for all users.