Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

when using a url that get a random image every time on multiple widgets, the same image result shows in all of them

all my Firestore documents contain a field called image_path, which has the Unsplash random source URL, https://source.unsplash.com/random/

enter image description here

as you can test, every time you opened that link it gives a different random image.
but in my flutter app, in the Image.network Row‘s children in SingleChildScrollView, all of them get the same random URL,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

       SingleChildScrollView(
            child: Row(
              children: List.generate(lengthOfDocuments),
              (index) => ImageBox(
                documentsList[index]["image_path"], // image_path == https://source.unsplash.com/random/
              ),
            ),
          );

but they show the same image :

what I am expecting:
that all images should get a randomly different image from that URL

what can be the reason for this behavior, and am I forgetting something?

>Solution :

There must be some kind of caching happening in the browser or on unsplash end.

Try making the url unique for each index like so:

documentsList[index]["image_path"] + `?index=${index}`

If that doesn’t change between page reloads then you could make the query param a random # or string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading