Fix subcomments duplicating on update

This commit is contained in:
John Wesley 2024-01-07 13:43:11 -05:00
parent 341dcc48d0
commit 7f4b2dea7a
2 changed files with 6 additions and 2 deletions

View File

@ -119,9 +119,11 @@ class _EntryCommentState extends State<EntryComment> {
.asMap() .asMap()
.entries .entries
.map((item) => EntryComment(item.value, (newValue) { .map((item) => EntryComment(item.value, (newValue) {
var newChildren = [...widget.comment.children!];
newChildren[item.key] = newValue;
widget.onUpdate(widget.comment.copyWith( widget.onUpdate(widget.comment.copyWith(
childCount: widget.comment.childCount + 1, childCount: widget.comment.childCount + 1,
children: [newValue, ...widget.comment.children!], children: newChildren,
)); ));
})) }))
.toList(), .toList(),

View File

@ -119,9 +119,11 @@ class _EntryCommentState extends State<PostComment> {
.asMap() .asMap()
.entries .entries
.map((item) => PostComment(item.value, (newValue) { .map((item) => PostComment(item.value, (newValue) {
var newChildren = [...widget.comment.children!];
newChildren[item.key] = newValue;
widget.onUpdate(widget.comment.copyWith( widget.onUpdate(widget.comment.copyWith(
childCount: widget.comment.childCount + 1, childCount: widget.comment.childCount + 1,
children: [newValue, ...widget.comment.children!], children: newChildren,
)); ));
})) }))
.toList(), .toList(),