3

I try display data from firestore using image url. i use FutureBuilder for get my image url value from firestore. but i have problem because my image cannot display and show red screen. i got messages in my debug console like :

Another exception was thrown: A build function returned null.

I/flutter (13506): Another exception was thrown: NoSuchMethodError: The method '[]' was called on null.

I/flutter (13506): Another exception was thrown: NoSuchMethodError: Class 'QuerySnapshot' has no instance method '[]'

and this my code :

ListTile(
  leading: new FutureBuilder(
    future: Firestore.instance.collection('users').where('uid', isEqualTo: _post['imgurl']).getDocuments(),
    builder: (BuildContext context, AsyncSnapshot snapshot){
      if(snapshot.hasData){
        if(snapshot.data != null){
          print(snapshot.data['imgurl']);
          return CircleAvatar(
            backgroundImage: NetworkImage(snapshot.data['imgurl']),
          );
        }
      }
    },
  ),
  title: Text('Richard');
)

can you tell me where is my fault?

1
  • can you database image sniped(cropped image).so after this.its easy to understand your code mistake. Commented Nov 12, 2020 at 13:54

3 Answers 3

2

Your Future returns a list of documents, not just one. You're trying to get a document's imageUrl from a list of document and not from one.

Your snapshot.data is a list of documents, you can find them in snapshot.data.documents.

If you're interested in just one document, I suggest you to change your Future to something that returns only one document (e.g. getting the first).

If you want to keep your Future as it is, just get the first document from your snapshot.data and do your work on it.

At this moment I can't provide further examples, since I'm not able to do it logistically (I'm not at home), but could provide you some if my suggestions do not help you resolve!

Sign up to request clarification or add additional context in comments.

1 Comment

yeah, thanks! I have tried that.. but why always show message like this : Another exception was thrown: A build function returned null. Another exception was thrown: NoSuchMethodError: The method '[]' was called on null.
0

Use

Image.network(widget.snapshot.data['imgurl'])

Here is how I handled the problem:

Card(
                              margin: EdgeInsets.symmetric(
                              horizontal: 10.0, vertical: 6.0),
                              elevation: 8.0,
                              child:
                              Image.network(
                                widget.ds.data['GraphImg'],
                                fit: BoxFit.contain,
                              ),                           )

worked for me!

Comments

0
FadeInImage.assetNetwork(
width: 50.0,
height: 50.0,
fit: BoxFit.cover,
image:ContentThumbnail.thumbnails[index],
placeholder: 'images/placeholder.jpg',),),

1 Comment

FadeInImage is the best for loading network image because of the placeholder which will show first until the right image is displayed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.