【发布时间】:2020-05-25 06:51:30
【问题描述】:
在这里,我尝试使用 streamBuilder 中的 firstore 实例从 firebase 数据库中获取 数据。
- .collection('/message_data/friendA##friendB/message_list') :-这是我从 firebase 收集的文档路径
没有错误,只是一个空白页。
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.friendName),
),
body: Column(
children: <Widget>[
Flexible(
child: StreamBuilder(
stream: Firestore.instance
.collection('/message_data/friendA##friendB/message_list')
.snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasError) {
return Text('Error on chatView ${snapshot.error.toString()}');
}
if (snapshot.connectionState == ConnectionState.active) {
if (snapshot.hasData) {
if (snapshot.data.documents .length > 0) {
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index) {
DocumentSnapshot _document = snapshot.data.documents[index];
return ChatMessage(
isFriend: _document['fromA'],
isNotPrevious:snapshot.data.documents.length - 1 == index,
message: _document['content'],
friendInitial: 'T',
avatarUrl:'https://avatarfiles.alphacoders.com/132/132399.jpg',
);
},
);
}
else{
return Text('No messages found in chat view length vala');
}
}
else{
return Text('No messages found in chat view hasdata');
}
}
else{
return CircularProgressIndicator();
}
},
)),
【问题讨论】:
-
尝试打印
_document。 -
@JohnJoe 什么都没有打印出来。
-
尝试调试。有没有到这个
if (snapshot.hasData)? -
@JohnJoe.Tried 也这样做了。不,它没有转到 if (snapshot.hasData)。
-
那么它去哪儿了?
标签: firebase flutter dart google-cloud-firestore mobile-development