[英]trying to get data from firestore but getting this ERROR
我正在嘗試從 Firebase Firestore 獲取數據並出現以下錯誤,相同的代碼在一個月前與我的其他應用程序一起工作,如果你能提供幫助,那就太好了
Class 'List' 沒有實例 getter 'lenght'。 接收器:“_GrowableList”的實例(長度:2) 嘗試調用: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',
),
),
],
)
],
),
),
),
),
);
},
));
}
}
變lenght
為length
我認為這是一個錯字。 如果你想知道為什么length
。 那是因為您正在嘗試獲取snapshot.data.documents
的長度並將其初始化為itemCount
以允許列表循環您的項目。 我希望這個解決方案適合你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.