2

I want to display the images with index through the urls stored in Firebase firestore, I am getting the images stored in cloud storage but I don't know how to get the url stored in firebase firestore which is in array. pls help me out as I am only a beginner and learning through internet. Image attached below. "users" then "userid" then "images"Thanks in advance.

List<String> urls = []; @override void initState() { super.initState(); _getImages(); } 

This is the container where images are displaying through urls stored in cloud storage.

 Container( height: 160.0, padding: EdgeInsets.symmetric(vertical: 15.0,horizontal: 15.0), child: CustomScrollView( physics: const BouncingScrollPhysics(), slivers: <Widget>[ SliverPadding( padding: const EdgeInsets.all(10), sliver: _buildContent(urls), ) ], ), ), 

This is method through which I am getting the images stored in cloud storage.

_getImages() async { ListResult _result = await _stoarge.ref().child("images").list(ListOptions(maxResults: 10)); _result.items.forEach((_ref) async { String _u = await _ref.getDownloadURL(); urls.add(_u); setState(() { print(urls.length); print(urls); }); }); } 

1 Answer 1

1

Put this in your getImages() function

//First, you must retrieve your document, like this: DocumentSnapshot firebaseDoc = await FirebaseFirestore.instance.collection('users').doc('yourDocumentId').get(); //then you need to extract your list, which is in the 'images' field, you can do so like this: List<String> imagesList = firebaseDoc.data()['images']; //Now, you have a list, containing the URLs you want. print(imagesList[0]); //should print the first URL, you can take it from here 
Sign up to request clarification or add additional context in comments.

8 Comments

thanks for the reply, but now I am getting this error. " Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<String>' "
change it to this: List imagesList = firebaseDoc.data()['images'];
still same error -- [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<String>'
sorry to bother you with new queries, now it is printing all the url in console but without the index, which I need at the time to delete image, but still it is not displaying in container, how to get them display and with index?
You don't need the index, you can just remove the element you want without having to pass the index.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.