flutterdartflutterflowdart-pdf

Looping through Firestore Documents to Display Elements


I'm attempting to loop through a list of documents from Firestore passed to a custom action in Flutterflow and display images according to the photo_url field contained in each document. I'm able to loop through and display strings from the document list, but images are where I'm having trouble.

I've tried including the images in the loop itself, using networkImage as per the "pdf" documentation on "https://pub.dev/packages/pdf", but ran into async/await issues as it was inside the "build" function. So I then placed a second loop at the beginning of my function to populate a list of images to be added to the pdf later during the loop in the build function, but the action fails when I attempt to use networkImage.

Loop:

final doc_imgs = [];
  for (final doc in docs) {
    if (doc.photoUrl.isNotEmpty) {
      final img = await networkImage(doc.photoUrl);
      doc_imgs.add(img);
    }
  }

Update: After further testing, networkImage works with other URLs, just not the ones passed by Firestore.


Solution

  • It looks like you're running into issues with displaying images from Firestore URLs using the networkImage function. Since you mentioned that the function works with other URLs but not with the ones retrieved from Firestore, there are a few things you can check and try to fix the problem:

    1. URL Format Validation:

    2. Firestore Storage Rules:

    3. CORS Issue:

    4. Async Handling in build:

    5. Alternative Image Loading: