Flutter : How to get the length of fields in one Firestore document?

Viewed 456

I want to get a total of fields in one document! but I didn't find an option for getting length. I'm getting only one document from firebase not a List of documents. Hope you understand my issue

final Stream<DocumentSnapshot<Map<String, dynamic>>> _Shop =
    FirebaseFirestore.instance
        .collection('shop')
        .doc('banana')
        .snapshots();



StreamBuilder<DocumentSnapshot>(
            stream: _ShopStream,
            builder: (BuildContext context,
                AsyncSnapshot<DocumentSnapshot> snapshot) {

              if (snapshot.connectionState == ConnectionState.waiting) {
                return Center(
                  child: CircularProgressIndicator(),
                );
              }
              if (!snapshot.data.exists) {
                return Center(
                  child: Text(
                    'Not Available !'.tr,
                    style: TextStyle(
                        fontSize: 20,
                        fontWeight: FontWeight.bold,
                        color: Colors.black),
                  ),
                );
              }
              DocumentSnapshot<Object> data = snapshot.data;

              return ListView.builder(
                itemCount: data.lenth,
                itemBuilder: (context, int index) {
                  return ListTile(
                    title: Text(data['banana']['name'].toString()),
                  );
                },
              );
            })
1 Answers
(data.data() as Map<String, dynamic>).keys.toList().length
Related