Flutter cache and retrieve images in same widget, is it possible? - firebase

Hei!
I have a quiz app that shows a list of active games. This list also shows the opponents profile image. The list is a stream from firestore.
Everytime the user changes to another screen and back to the gamelist the images are downloaded again..this uses alot of network traffic.
I cant put the images in cache when the app starts as i dont know what games the player have, and they are changing. Is there a way to get the image from url , put it in cache, and IF its in cache , use that image..in the same widget?

I believe cached_network_image package is what you need.

Related

How can I refresh an individual List Tile in a Listview.builder? Flutter

Situation:
I have an 'Event' item that you can click on --> Event detail screen.
That has individual subitems (date,participants,description) in the form of a list.
I load the subitems with a Future Builder into a Listview.builder with a List Tile like so:
I have a button to edit the location, it saves to the database and locally updates the location variable. This calls SetState().
The full list is updated, even if some tiles don't have changes.
THE PROBLEM
Some tiles, like the participants tile needs to load pictures and some other things that are time intensive. So even if I just change the location and update the list, everything reloads, consuming resources and taking too much time to load a simple string.
WHAT I AM LOOKING FOR
Is it possible to reload only a certain list tile? Would you use another widget instead of ListView.builder? Other logic? Any help is appreciated.
Answer Extension [Update]
The marked answer is correct. I was using future builder and that was forcing me to reload all data always. By using different Streams with Streambuilder I am able to change data on database and it automatically changes on the UI, without updating the state! Magic.
base on what i notices, Future Builder is the problem, Future builder rebuild the whole widget in the ListView.builder. in your case use StreamBuilder and you see the changes you what...

Is it possible to specify the SIZE of image requests from https://firebasestorage.googleapis.com/?

When utilising Firebase Storage to store imagery, for example, user avatars, is there a way that you can request a smaller, thumbnail sized serving of the image?
I have searched Google and documentation and I have been unable to come up with a result. Currently my app utilising Firebase Storage URLs experiences a minor delay prior to loading images due to the fact that it I am requesting large images to fill tiny avatars.
Is there a resource I am overlooking that specifies the available parameters for this URL? (of which token & alt are two I'm aware of).
Thank you for the assistance in advance.
Auto-resizing images upon read is not a feature of Firebase Storage. The typical solution is to create variants of the images during upload, for example through the Resize Images extension.

Firebase Storage Flutter Displaying images takes too long to load

I'm creating sort of a tutorial application and have to display images from firebase storage with a step-by-step tutorial. Currently I'm using the .getDownloadUrl function and am displaying the images using Cached Network Images(External library) with the URL. The images are replaced when the step is completed and it takes at least 2-3 seconds to load an image and can get quite irritating for a user. Also, to minimize latency I shifted the Cloud Storage location nearby to where a user would be, this improved the speed slightly. Is there a better way to display images, apart from storing the links on Cloud Firestore or saving all the URLs in one list at the start.
The most common approach is to compress/resize (or both) your images. By doing this you have a few options:
1. You can display the thumbnail by default and only load the full image (or load it in the background) when the user requests it (eg. they click on details about the tutorial)
2. Load a different version of the image depending on the screen size (you don't need to display an image meant for desktop on a mobile device)
3. Replace the old image with the compressed one. Depending on what the content is, you probably don't need images larger than 200kb, and that's being generous.
You could also consider storing your images using a next gen format, such as WebP as it is considered one of the most efficient image types. But, it's not yet supported on all devices, so you'd want to include a fallback type.
You said you're caching the images which is a good step to reduce load times. You also said you shifted the storage location to be closer to the users. You could also try to find a CDN that is even closer to your user's locations (probably diminishing returns).
You seem to be against storing the downloadUrls in your database. This would help as all you'd have to do is load the image, instead of ping the bucket for the url and then load it.
Another potential solution for your use case could be to download the images for this tutorial, as well as the next one so when the user clicks next the images are already downloaded.
Unfortunately there isn't a lot else you can do. There's a lot of data packed into an image and it takes some time to load and render it

Flutter/Dart/Firebase - Reduce unnecessary data loading

I tried searching my specific problem but I could not find any suitable solution.
I would like to thank everybody in advance for your help.
I am currently developing an iOS app.
The App represents a user profile which can be updated by the user.
Everything from the authentication, registration and the possibility to update your user data works fine with the help of Firebase. Now I would like to optimize some code.
So the application has 2 Screens, HomeScreen and EditScreen.
(Besides the Screens needed for registration and login).
To keep my question short:
How can I reduce the amount of data which is loaded from firebase?
Example:
1. User is on the HomeScreen, to build the view his image loads from Firebase Storage
2. He wants to edit his Image and therefore switches to the Editscreen, where his image will be loaded again
3. After changing his image, the new image will be uploaded to Firebase Storage and he can see his new image on the Editscreen
4. If he now switches back to the HomeScreen his new image will be loaded again from Firebase
Is there a good way to reduce the amount of loading?
Like caching the image between step 1 and 2?
As there is always a little delay in displaying his image.
Thanks!
Sadly I am not allowed to share any code.
You can check out the flutter_advanced_networkimage package. It will cache your photo upon load. For everything else, you should just move your profile object (or whatever it is that calls for the firebase user's information) above those routes and pass it down through your widget tree through arguments or state management.

Synchronise 2 youtube videos on Drupal site

I want to allow 1 user to point to a youtube video (possibly upload it through the youtube api) on a Drupal site.
And then other users can add videos linked to that video (separate nodes?).
The difficulty is that the videos should be synchronised. So when a user uploads a video to match the original one, he should be able to somehow indicate how this is synchronised with the original one. For instance 4seconds vid1 = 1second vid2
Any ideas, module suggestions, UI ideas are very much appreciated.
I have found this post on video synchronisation with youtube api, but I need a method that would allow the user to actually easily give in the synchronisation. And then synchronise with different starting times.
Best to create a custom module for that. Give the user a form with the youtube id and a sync time then use the youtube api from there. No need for drupal specific code - tho you could create seperate nodes for each video, relate them with node reference fields and store any data in the variables table - butI'd probably create my own table for this.

Resources