From 7f4b2dea7a103bd7a7eb01df817cb251be0ac356 Mon Sep 17 00:00:00 2001 From: John Wesley Date: Sun, 7 Jan 2024 13:43:11 -0500 Subject: [PATCH] Fix subcomments duplicating on update --- lib/src/screens/entries/entry_comment.dart | 4 +++- lib/src/screens/posts/post_comment.dart | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/src/screens/entries/entry_comment.dart b/lib/src/screens/entries/entry_comment.dart index 4d7668c..b757b85 100644 --- a/lib/src/screens/entries/entry_comment.dart +++ b/lib/src/screens/entries/entry_comment.dart @@ -119,9 +119,11 @@ class _EntryCommentState extends State { .asMap() .entries .map((item) => EntryComment(item.value, (newValue) { + var newChildren = [...widget.comment.children!]; + newChildren[item.key] = newValue; widget.onUpdate(widget.comment.copyWith( childCount: widget.comment.childCount + 1, - children: [newValue, ...widget.comment.children!], + children: newChildren, )); })) .toList(), diff --git a/lib/src/screens/posts/post_comment.dart b/lib/src/screens/posts/post_comment.dart index 2d71c2a..79d38ba 100644 --- a/lib/src/screens/posts/post_comment.dart +++ b/lib/src/screens/posts/post_comment.dart @@ -119,9 +119,11 @@ class _EntryCommentState extends State { .asMap() .entries .map((item) => PostComment(item.value, (newValue) { + var newChildren = [...widget.comment.children!]; + newChildren[item.key] = newValue; widget.onUpdate(widget.comment.copyWith( childCount: widget.comment.childCount + 1, - children: [newValue, ...widget.comment.children!], + children: newChildren, )); })) .toList(),