我遇到了奇怪的问题,我不知道问题的原因。
问题不存在,但突然出现。我有使用两个streambuilder的聊天列表,每个包含名称和个人资料图片。问题是它出现的矩形位置太长 名称和消息,我不知道为什么。
出现问题之前
出现问题后:
“运行”标签中的错误
符号: 在Simulator上可以正常工作,但是在实际设备上,问题仍然显示。
我的代码:
body: ListView(
children: <Widget>[
Column(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
child: Stack(
children: <Widget>[
StreamBuilder(
stream: Firestore.instance
.collection(MESSAGES_COLLECTION)
.document(widget.myuid)
.collection(CHAT_MESSAGES)
.orderBy('timestamp',descending: true)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
const Text('Loading...');
} else {
return ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot mymessage =
snapshot.data.documents[index];
return Stack(
children: <Widget>[
Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
),
child:StreamBuilder(
stream: Firestore.instance
.collection(MESSAGES_COLLECTION)
.document(widget.myuid)
.collection(CHAT_MESSAGES)
.document(mymessage.documentID)
.collection(BETWEEN_US)
.orderBy('timestamp',descending: true)
.snapshots(),
builder: (context, snapshot){
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return SizedBox();
case ConnectionState.active:
default:
break;
}
if (snapshot.hasError) print(snapshot.error);
DocumentSnapshot lastmessege = snapshot.data.documents[0];
return StreamBuilder(
stream: Firestore.instance
.collection(USERS_COLLECTION)
.where('uid', isEqualTo: mymessage.documentID)
.snapshots(),
builder: (context, snapshot){
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return SizedBox();
case ConnectionState.active:
default:
break;
}
if (snapshot.hasError) print(snapshot.error);
DocumentSnapshot user = snapshot.data.documents[0];
return InkWell(
onTap: () {
if (mymessage.documentID
.toString() !=
widget
.myuid
.toString()) {
User userMessage = User(
devtoken: user['devtoken'],
devlang: user['devlang'],
uid: user['uid'],
name: user['name'],
username: user['uname'],
profilePhoto: user['uimg'],
);
Navigator.push(context, MaterialPageRoute(
builder: (context) => ChatScreen(
myapplang: widget.myapplang,
receiver: userMessage,
)
));
}
},
child: ListTile(
contentPadding:
EdgeInsets
.symmetric(
horizontal:
10.0,
vertical:
20.0),
leading: ClipRRect(
borderRadius:
BorderRadius.circular(
35.0),
child: CachedNetworkImage(
imageUrl: user[
'uimg'],
width: 50.0,
height: 50.0,
),
),
title: Flexible(child: Text(user['name'],style: TextStyle(color: Colors.white,fontSize: 18),),),
subtitle: lastmessege['message'] != "IMAGE" ? Text(lastmessege['message'],style: TextStyle(color: Colors.white,fontSize: 15),) :
Padding(
padding: EdgeInsets.only(top: 15.0,left: 25.0),
child: Align(
alignment: Alignment.centerLeft,
child: ClipRRect(
borderRadius:
BorderRadius.circular(
5.0),
child: CachedNetworkImage(
imageUrl: lastmessege['uimg'],
height: 40,
width: 40,
),
),
),
),
// subtitle: Text("Intermediate", style: TextStyle(color: Colors.white)),
),
);
},
);
},
),
),
Divider(color: Colors.purple,),
],
),
],
);
});
}
return Container(
height: 0.0,
width: 0.0,
);
},
),
],
),
),
],
),
],
),