![](/img/trans.png)
[英]Flutter Cloud Firestore: error: The argument type 'Object? Function()' can't be assigned to the parameter type 'Map<String, dynamic>'
[英]Flutter: How to solve value type Object can't be assigned to Map<String, dynamic> on streambuilder
我試圖從 firebase 獲取數據並將數據顯示到列表中,但在嘗試將 map 文檔數據放入列表以顯示其內容時出現錯誤
這是我的代碼
StreamBuilder<QuerySnapshot>(
stream: users.snapshots(),
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return const Center(
child: Text("Something went wrong"),
);
}
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: Text("Loading"),
);
}
if (snapshot.hasData) {
return CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildListDelegate(
snapshot.data!.docs.map(
(DocumentSnapshot document) {
Map<String, dynamic> data = document.data()!;
return ListTile(
onTap: () => callChatDetailsScreen(
context, data['name'], data['uid']),
title: Text(data['name']),
subtitle: Text(data['status']),
);
},
).toList(),
),
)
],
);
}
return Container();
})
我怎樣才能解決這個問題?
改變這個:
(DocumentSnapshot document) {
進入這個:
(DocumentSnapshot<Map<String,dynamic>> document) {
data()
data()
T
類型的值,class DocumenSnapshot
以這種方式聲明: abstract class DocumentSnapshot
abstract class DocumentSnapshot<T extends Object?>
Object
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.