【发布时间】:2025-12-10 20:35:02
【问题描述】:
在我的应用程序中,我正在尝试创建一个 cmets 部分。在本节中,我希望用户能够以类似于 YouTube 应用的方式回复其他用户的评论。我已经设法创建了一个显示* cmets 的模态底部表,并且在几个流构建器的帮助下它运行良好。但是,我面临的问题是二级cmets(回复人们的cmets。)。我想让它让用户点击评论并被带到一个页面(仍然在模态底部表中),在那里他可以看到对评论的所有回复并且也可以自己发表评论,如果他回击,他会去立即回到他所在的位置,并且可以继续滚动浏览* cmets。
类似于 YouTube 应用的外观。 我有在底部表中使用 Navigator.push 的想法,在模态底部表中当前现有页面的顶部覆盖一个新页面,在这个新页面中,特定评论的第二级 cmets(回复)是被显示。但是,当我调用 Navigator.push 时,整个页面都会发生变化。整个父页面转移到新页面,而不仅仅是底部表格中的内容。所以,这是我的问题。我对想法持开放态度。
我的评论底页背后的代码:
showModalBottomSheet(
context: context,
builder: (context) {
return
Container(
child: StatefulBuilder(
builder: (BuildContext context, setTheModalState) {
setModalState = setTheModalState;
return Container(
child: Column(
children: <Widget>[
Expanded(
child: StreamBuilder(listview))])}))}
这是我迄今为止设计的。现在棘手的一点是在按下回复按钮(消息图标)时在模式表中创建一个新页面
评论区代码:
showModalBottomSheet(
context: context,
builder: (context) {
return
Container(
child: StatefulBuilder(
builder: (BuildContext context, setTheModalState) {
setModalState = setTheModalState;
return Container(
child: Column(
children: <Widget>[
Expanded(
child: StreamBuilder(
stream: Firestore.instance
.collection("Replies")
.document(dream.documentID)
.collection(dream.documentID)
.orderBy('time', descending: true)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: SpinKitDoubleBounce(
color: Colors.blue,
),
);
} else {
dynamic replies = snapshot.data.documents;
return ListView.builder(
itemCount: replies.length,
reverse: true,
itemBuilder: (context, index) {
if (replies[index]["text"] != "" &&
replies[index]["images"] == null) {
return _buildStringCommment(
replies[index], true);
} else {
if (replies[index]["images"].length == 1) {
return _buildCommentFromOneImage(
replies[index], true);
} else {
if (replies[index]["images"].length == 2) {
return _buildCommentFromTwoImages(
replies[index], true);
} else {
if (replies[index]["images"].length ==
3) {
return _buildCommentFromThreeImages(
replies[index], true);
} else {
if (replies[index]["images"].length ==
4) {
return _buildCommentFromFourImages(
replies[index], true);
} else {
if (replies[index]["images"].length ==
5) {
return _buildCommmentFromFiveImages(
replies[index], true);
} else {
return _buildMessageFromMoreThanFiveImages(
replies[index], true);
}
}
}
}
}
}
},
);
}
},
),
),
theTypeReplyThingie(dream, context, true)
],
),
);
},
),
);
},
);
“type reply thingie”是具有文本输入表单和发送按钮的小部件。
【问题讨论】:
-
让我再澄清一下这个问题。我已经设法展示了底页和第一级 cmets。但我希望当用户点击评论时,他会被带到一个新页面(在底部表格内),其中显示了对评论的回复。有关我的意思的示例,请查看 youtube 应用程序。他们的评论系统与我正在尝试制作的类似。我已经创建了底部工作表并进行了*评论。我想不通的是如何使用 Navigator.push 在模态表中创建一个新页面,其中显示了对 cmets 的回复。
标签: flutter flutter-layout flutter-navigation