[英]Flutter : How to get the length of fields in one Firestore document?
我想获得一个文档中的总字段数。 但我没有找到获取长度的选项。 我只从 firebase 得到一份文件,而不是文件列表。 希望你理解我的问题
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()),
);
},
);
})
(data.data() as Map<String, dynamic>).keys.toList().length
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.