I have been working on an e-commerce app. As there are a lot of images to be loaded for product listing I tried to cache the images using flutter_advanced_networkimage: ^0.7.0, and cached_network_image 2.5.0 packages. It seems that images are cached and loaded only if the app is in memory.
ie: if the os kills the app or user closes the app from the background the cached data lost.
Is there any better way to cache images for use-cases like e-commerce?
Thanks.
Related
I have multiple projects using Google Firebase and am using Firebase Storage to store my images and load them on mobile devices. The mobile app is developed on Flutter.
The marketplace app project loads images pretty quick, while the other app is very slow with the loads [nearly 5 seconds :(]
Below are the links to pics from each project. First one, being 900+kb loads pretty quick, but second one being 77kb takes much longer. What I see is the webpage itself takes so much time to load when open in the browser. At first I thought it must be the loading and caching in the app but now since it behaves differently on the browser to load, I am confused.
I am not sure maybe I am overlooking at some settings. Please help :)
https://firebasestorage.googleapis.com/v0/b/revivemarketplace-e61ec.appspot.com/o/03523bc0-cb82-11eb-a754-47c8b7348079?alt=media&token=ec7d02d5-7f6b-4493-9c99-6d2e9ac53da2
https://firebasestorage.googleapis.com/v0/b/diaeh/o/resized1000%2F00000apexels-christina-morillo-1181244_1000x1000.jpg?alt=media&token=b698c7ae-38ab-41ac-8761-bc6f4f18d98a
you can try this formula
Reupload your pic to firebase and set new link to your app of image
Hi everyone I need help with downloading images in background in our flutter app
We are showing users list of images in our app we need to allow users to select these images and save them to thier phone but the download has to happen in the background so that the user can continue using rest of the features of the app
Our app is developed in flutter
Our backend is written in laravel 8
And database is SQL
I am a newbie and so I don't have much clarity regarding what more information shud I put in to help you all understand the code so I am adding a screenshot of the UI of our app search page
where we need to allow users to select multiple images and save them to their phone local storage but the download has to happen in background as the image size is big
You can use a async function where you call it and the app goes on. In the background all images are going to be saved on the phone while you still can use the app
My app uses a-lot of cached images which (I think is the reason causing my app to crash) when i scroll to view so many at one time.
My app is all about images inside list/grid view.
Is it good practice to cache them all?
Note:
Please note I'm using SliverGrid which is loading images lazily.
If you going to manage a buch of amount image is better, download them to a local directory and take the url like a name in a Data Base then you can ask on every request if your url is on your data base if is there then the file in your directory exist if not, you do the request and store it file in directory and name on db. This is better when your app manage a buch of information in cache like image, because on some devices the app can be crash o even restar the device.
I am trying to store images locally while the user is running the app and also keep the images stored locally while the app is in the background. When the user terminates the app, then the data should disappear locally and only be loaded once the user reopens the app. I know how to load the images initially, but I am considering where/how to store the images locally.
I know that Swift has the file system, but I was wondering if this is the best practice for this kind of implementation or if there is a better solution.
Doing exactly what you want is not possible, but you can do something similar in functionality.
To cache images you can simply use an existing library, like SDWebImage. It manages asynchronous image downloading and caching for you, and to clear cached images you can simply do
SDImageCache.sharedImageCache().clearMemory()
SDImageCache.sharedImageCache().clearDisk()
Now, as for when you want to clear the cache, it get's a little tricky.
You can't clear the cache when terminating the app, because there is no way to reliably detect when the app is terminated. There is UIApplicationDelegate.applicationWillTerminate method, but it is not called if the app is terminated while in suspended state.
But you can do a workaround: simply clear the cache upon launching the app in UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:), which will be functionally equivalent of what you want to do.
I am creating an app where the user will select some photos for the avatars used in the app. Once selected, on the next launch I want to populate the avatars automatically.
Solution I am Thinking: I will keep a duplicate of the original photo in the app directory and next time I will use the photo to make the avatars.
Issue: Not efficient as the same copy of the image exists.
Question: Since many apps are doing this thing, I want to know the best way to do that, more specifically in Flutter?
Use the cached_network_image plugin.
This plugin allows you to download an image from the internet and cache it in the app for later. You can provide a placeholder image that sits there while no image has been loaded yet(from the web or the internal cache) and also what to show in case of error. If the device goes offline cached_network_image automatically will load the image from the cache, it's transparent to your app, you don't have to bother with the cache, storage space, database, anything.
Take a look at the docs.
There are no best practices in this regard. It depends on your app.
1) Storing your avatars
Takes more storage space. But your app runs faster.
Best when the number of avatars displayed on a single screen is high, but the total number of avatars in your app is small. (E.g.: you show 15 avatars on a single screen, and there are 100 avatars in your database).
2) Generating your avatars
Takes less space. But your app runs slower.
Best when the number of avatars displayed on a single screen is low, but the total number of avatars in your app is large. (E.g.: you only show 3 avatars on a single screen, but there are 100.000 avatars in your database).
Conclusion
Speed is usually more important than storage space, therefor I'd lean towards storing the avatars. But the only true way to get an answer is to test it and see what works best for your specific app.
I think you must copy the original photo, Most people use cloud service(google photos etc.) for their photos and not keep photos on phones any more..
use cached images widget to store images for some time or use SQLite database for long time in device .