稅務頁面上的檔案不會出現在螢屏上。我得到以下 _CastError (空值上使用的空檢查運算子)。有沒有人可以幫忙?
firestore_db_services.dart
@override
Stream<List<Vergi>> getHizmetler(String currentUserID) {
var snapShot = _firebaseFirestoreDB
.collection("hizmetler")
.doc(currentUserID)
.collection("vergi")
.orderBy("aciklamaDate")
.snapshots();
return snapShot.map(
(vergiListesi) => vergiListesi.docs
.map(
(vergi) => Vergi.fromMap(vergi.data()),
)
.toList(),
);
}
vergidart
Expanded(
child: StreamBuilder<List<Vergi>?>(
stream: _userModel.getHizmetler(_currentUser.userID),
builder: (context, snapShot) {
if (snapShot.hasError) {
return Center(
child: MyIndicator(),
);
}
if (snapShot.connectionState == ConnectionState.waiting) {
return Text("Yükleniyor...");
}
List<Vergi>? tumVergiListesi = snapShot.data;
return ListView.builder(
itemCount: tumVergiListesi!.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(
tumVergiListesi[index].aciklama.toString(),
),
subtitle: Text(
tumVergiListesi[index].fiyat.toString(),
),
);
},
);
},
),
),
uj5u.com熱心網友回復:
嘗試從getHizmetler函式回傳快照而不是您當前回傳的串列:
Stream<QuerySnapshot>getHizmetler(String currentUserID) {
return _firebaseFirestoreDB
.collection("hizmetler")
.doc(currentUserID)
.collection("vergi")
.orderBy("aciklamaDate")
.snapshots();
}
調整你的StreamBuilder喜好:
StreamBuilder<QuerySnapshot>(
stream: _userModel.getHizmetler(_currentUser.userID),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
// error handling
return ...;
}
if (snapshot.connectionState == ConnectionState.waiting) {
// progress indicator
return ...;
}
if (snapshot.hasData) {
// here you can do the conversion you like, result will be in:
// snapshot.data!.docs
}
}
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/377570.html
標籤:火力基地 扑 镖 谷歌云firestore
上一篇:我的專案使用'>=2.14.4<3.0.0'的dart,但是執行'>=2.11.9<3.0.0'會洗掉空安全。所以它會從這個范圍中選擇&
