我无法从 Firebase 访问 UID


  1. 我无法从firebase访问uid。我试了很多次。有人能帮我解决这个问题吗?
class Massages extends StatelessWidget {

@override   Widget build(BuildContext context) {
return FutureBuilder(
future: Future.value(FirebaseAuth.instance.currentUser),
builder: (ctx, futureSnapshot) {
if (futureSnapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
return StreamBuilder(
stream: FirebaseFirestore.instance
.collection('chat')
.orderBy('createdAt', descending: true)
.snapshots(),
builder: (ctx, AsyncSnapshot<dynamic> chatSnapshot) {
if (chatSnapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
return ListView.builder(
reverse: true,
itemCount: chatSnapshot.data!.docs.length,
itemBuilder: (ctx, index) => MessageBubble(
chatSnapshot.data!.docs[index]['text'],
chatSnapshot.data!.docs[index]['userId'] ==
futureSnapshot.data?.uid,
key: ValueKey(chatSnapshot.data!.documentID),
),
);
});
});   } }

看起来futureSnapshot.data返回的是Object而不是User。您可以尝试使用

将其转换为正确的类型:
((User)futureSnapshot.data)?.uid,

相关内容

  • 没有找到相关文章

最新更新