我試圖從Firestore讀取我的uid1和uid2檔案中的所有欄位。我的代碼崩潰了,因為fromJson不能將imageList從陣列轉換為串列。
Future<List<AppClient>> getClientListResult(List<String> listId) async{
final List<AppClient> clientList = <AppClient> [];
print(listId)。
final QuerySnapshot<Map< String, dynamic>> snapshot = await _firestore. collection('client').where('uid', arrayContainsAny: listId).get()。
final List<AppClient> result = snapshot.docs. map((QueryDocumentSnapshot<Map<String, dynamic>> doc) => AppClient.fromJson(doc.data()) ).toList()。
clientList.addAll(result)。
return clientList;
}
uj5u.com熱心網友回復:
你可以使用rxdart來結合兩個來自Firestore的集合,使用這個插件rxdart
sample code
StreamBuilder(
流。CombineLatestStream.list([
火店
.collection('users')
.doc(data['id'])
.snapshots()。
火店
.collection('Image')
.doc(data['id'])
.collection('Photos')
.orderBy('timestap')
.snapshots()。
]),
建設者。(context, snapshotid) {
//這里是第一個資料流。
final active = snapshotid.data[0].data()。
//這里是第二個流的情況。
final active1 =
snapshotid.data[1].docs[0].data()。
uj5u.com熱心網友回復:
你的AppClient類應該看起來與此類似:
你的AppClient類應該看起來與此類似:
class AppClient {
String地址。
String email;
List<String> imageList;
String name;
String price;
double rating。
List<String> uid。
啟用AppClient(
{this.address,
this.email,
this.imageList,
this.name。
this.price,
this.評級。
this.uid})。)
AppClient.fromJson(Map<String, dynamic> json) {
地址 = json['address']。
email = json['email']。
imageList = json['imageList'].cast<String>()。
name = json['name']。
價格 = json['price'];
rating = json['rating']。
uid = json['uid'].cast<String>()。
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>()。
data['address'] = this.address。
data['email'] = this.email。
data['imageList'] = this.imageList;
data['name'] = this.name。
data['price'] = this.price。
data['rating'] = this.rating。
data['uid'] = this.uid;
return data;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/325754.html
標籤:

