0

i am trying to get data from Firebase Firestore and getting the following error, the same code was working a month ago with my other app, it would be great if you could help

Class 'List' has no instance getter 'lenght'. Receiver: Instance(length:2) of '_GrowableList' Tried calling: lenght

    return Scaffold(
                body: StreamBuilder(
          stream: FirebaseFirestore.instance
              .collection('Sell')
              .orderBy('TS', descending: true)
              .snapshots(),
          builder: (context, snapshot) {
            if (snapshot.data == null)
              return Center(
                child: CircularProgressIndicator(
                  backgroundColor: Colors.red,
                  valueColor:
                      new AlwaysStoppedAnimation<Color>(Colors.cyan[400]),
                ),
              );
            return ListView.builder(
              itemCount: snapshot.data.documents.lenght,
              itemBuilder: (context, index) => SingleChildScrollView(
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Container(
                    height: 120,
                    width: MediaQuery.of(context).size.width,
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(7),
                        boxShadow: [
                          BoxShadow(
                              color: Colors.grey[400],
                              spreadRadius: 2,
                              blurRadius: 3)
                        ]),
                    child: Row(
                      children: [
                        Container(
                          width: 120,
                          height: 120,
                          child:ClipRRect(
                                 child: Image.network(
                                    snapshot.data.documents[index]
                                        .get('image 1 Url'),
                                    fit: BoxFit.cover,
                                  ),
                                )),
                        SizedBox(width: 20),
                        Column(
                          children: [
                            Text(
                              snapshot.data.documents[index].get('name'),
                              style: TextStyle(
                                color: Colors.red,
                                fontSize: 20,
                                fontFamily: 'font',
                              ),
                            ),
                          ],
                        )
                      ],
                    ),
                  ),
                ),
              ),
            );
          },
        ));
  }
}

1 Answer 1

1

Change lenght to length

That's a typo i think. If you wondering why length. That's because you are trying to get the length of snapshot.data.documents and initialise it to itemCount to allow the list to loop your item. I hope this solution works for you.

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

Comments

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.