[英]Flutter Page refresh problem | ListView showing a error “BOTTOM OVERFLOWED BY 98 PIXEL”
I am working a messaging app based on firebase.我正在开发一个基于 firebase 的消息应用程序。 I am a having problem in the home page.我的主页有问题。 I created the home page to show the last message, the user name, and the profile pic of the user who send the message.我创建了主页以显示最后一条消息、用户名和发送消息的用户的个人资料图片。 But when I am getting back from the chatscreen only the last message is updating.但是当我从聊天屏幕回来时,只有最后一条消息正在更新。 And the last message did not showing the correct user who send the message.最后一条消息没有显示发送消息的正确用户。 But after hot reload it is showing correctly.但是热重载后它显示正确。 And the ListView builder did not scrolling.并且 ListView 构建器没有滚动。 It is showing a error "BOTTOM OVERFLOWED BY 98 PIXEL".它显示错误“BOTTOM OVERFLOWED BY 98 PIXEL”。 How can I fixed those problems?我该如何解决这些问题?
Widget chatRoomsList() {
return StreamBuilder(
stream: chatRoomsStream,
builder: (context, snapshot) {
return snapshot.hasData
? ListView.builder(
itemCount: snapshot.data.docs.length,
shrinkWrap: true,
itemBuilder: (context, index) {
DocumentSnapshot ds = snapshot.data.docs[index];
return ChatRoomListTile(ds.id, ds["lastMessage"], myUserName);
})
: Center(child: CircularProgressIndicator());
},
);
}
ChatRoomList Tile:聊天室列表磁贴:
class _ChatRoomListTileState extends State<ChatRoomListTile> {
String profilePicUrl = "", name = "", username = "";
getThisUserInfo() async {
username =
widget.chatRoomId.replaceAll(widget.myUserName, "").replaceAll("_", "");
QuerySnapshot querySnapshot = await DatabaseMethods().getUserInfo(username);
print("something the data we are getting ${querySnapshot.docs[0].id}");
name = "${querySnapshot.docs[0]["name"]}";
profilePicUrl = querySnapshot.docs[0]["imgUrl"];
setState(() {});
}
@override
void initState() {
getThisUserInfo();
super.initState();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
before going to charRoom
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatScreen(
username,
name,
),
));
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(30),
child: Image.network(
profilePicUrl,
height: 40,
width: 40,
),
),
SizedBox(width: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(name,
style: TextStyle(
fontSize: 16,
color: Colors.white,
)),
SizedBox(height: 3),
Container(
width: 200,
child: Text(
widget.lastMessage,
style: TextStyle(
fontSize: 16,
color: HexColor("#E6F4F7"),
),
overflow: TextOverflow.visible,
softWrap: false,
),
),
SizedBox(height: 30),
],
),
],
),
);
}
}
Full home page code: https://github.com/Monzim/messengerClone/blob/main/lib/views/home.dart完整主页代码: https://github.com/Monzim/messengerClone/blob/main/lib/views/home.dart
I just updated my answer you can put this code into your Home class
我刚刚更新了我的答案,您可以将此代码放入您的Home class
Column(
children: [
Row(
children: [
...// Your Child
],
),
isSearching ? Expanded(child: searchUserList()) : Expanded(child: chatRoomsList(),
],
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.