I have a ListView with comments items and every comment has a new ListView with comment reply, I've used Firebase and when I replied to comment it is showing the wrong text on ListView but in console correct text is printed. When I go back and come again it shows the correct value. Watch video for clarification.
Padding(
padding: EdgeInsets.only(left: 0.0),
child: StreamBuilder(
stream: getCommentReply(listMessage[index]['id']),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(child: Text(''));
}
var listReplyMessage = snapshot.data.documents;
return Padding(
padding: EdgeInsets.only(top: 8.0),
child: commentsReplyItems(listReplyMessage,
snapshot, listMessage[index]['id']));
}))
Widget commentsReplyItems(
var listMessage, AsyncSnapshot snapshot, String commentID) {
return CommentReplay(
listMessage, snapshot, commentID, widget.currentUser, widget.postID);
}
Stream<QuerySnapshot> getCommentReply(String msgID) {
Stream<QuerySnapshot> _query = Firestore.instance
.collection('Posts')
.document(widget.postID)
.collection('Comments')
.document(msgID)
.collection('Reply')
.orderBy('created_at', descending: true)
.limit(2)
.snapshots();
return _query;
}
Comment Reply Item
class CommentReplay extends StatefulWidget {
List<dynamic> listMessage;
AsyncSnapshot snapshot;
String commentID;
FirebaseUser currentUser;
String postID;
CommentReplay(this.listMessage, this.snapshot, this.commentID,
this.currentUser, this.postID);
@override
_CommentReplayState createState() => _CommentReplayState();
}
class _CommentReplayState extends State<CommentReplay> {
var _key = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
key: _key,
physics: ClampingScrollPhysics(),
itemCount: widget.snapshot.data.documents.length,
itemBuilder: (context, position) {
//print(position);
return Container(
padding: EdgeInsets.only(top: 5.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
widget.listMessage[position['commentText'],
textStyle: TextStyle(
fontSize: 16.0,
color: Color(0xff0D0E15)),
textAlign: TextAlign.start,
)
],
),
);
});
}