Skip to content

Commit 3b69ace

Browse files
committed
fix(community_management): use ValueWrapper to set nullable values
- Replace manual Engagement creation with originalEngagement.copyWith() - Use ValueWrapper to explicitly set comment to null or resolved status - Remove unnecessary TODO comment - Update core dependency to latest version
1 parent b5aabaf commit 3b69ace

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

lib/community_management/bloc/community_management_bloc.dart

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,10 @@ class CommunityManagementBloc
298298
if (originalEngagement.comment == null) return;
299299

300300
final updatedEngagement = originalEngagement.copyWith(
301-
comment: originalEngagement.comment!.copyWith(
302-
status: ModerationStatus.resolved,
301+
comment: ValueWrapper(
302+
originalEngagement.comment!.copyWith(
303+
status: ModerationStatus.resolved,
304+
),
303305
),
304306
);
305307

@@ -334,21 +336,9 @@ class CommunityManagementBloc
334336
(e) => e.id == event.engagementId,
335337
);
336338

337-
// TODO(fulleni): Fix the following BUG
338-
// The original Engagement.copyWith method has a bug where
339-
// `comment: comment ?? this.comment` prevents setting the comment to null.
340-
// To work around this without modifying the core model, we must create a
341-
// new instance of Engagement manually, copying all properties and
342-
// explicitly setting the comment to null.
343-
final updatedEngagement = Engagement(
344-
id: originalEngagement.id,
345-
userId: originalEngagement.userId,
346-
entityId: originalEngagement.entityId,
347-
entityType: originalEngagement.entityType,
348-
reaction: originalEngagement.reaction,
349-
createdAt: originalEngagement.createdAt,
350-
updatedAt: DateTime.now(),
351-
comment: null, // Explicitly set to null to reject/delete the comment.
339+
final updatedEngagement = originalEngagement.copyWith(
340+
// Use ValueWrapper to explicitly set the comment to null.
341+
comment: const ValueWrapper(null),
352342
);
353343

354344
final updatedEngagements = List<Engagement>.from(state.engagements)

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ packages:
8989
dependency: "direct main"
9090
description:
9191
path: "."
92-
ref: "8bae6eb17369b76f72961870a22ee13d3073fa61"
93-
resolved-ref: "8bae6eb17369b76f72961870a22ee13d3073fa61"
92+
ref: b3bf1fbe84c51006c55c0eed7fb5de2f11a95208
93+
resolved-ref: b3bf1fbe84c51006c55c0eed7fb5de2f11a95208
9494
url: "https://github.com/flutter-news-app-full-source-code/core.git"
9595
source: git
9696
version: "1.3.1"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ dependency_overrides:
9494
core:
9595
git:
9696
url: https://github.com/flutter-news-app-full-source-code/core.git
97-
ref: 8bae6eb17369b76f72961870a22ee13d3073fa61
97+
ref: b3bf1fbe84c51006c55c0eed7fb5de2f11a95208
9898
http_client:
9999
git:
100100
url: https://github.com/flutter-news-app-full-source-code/http-client.git

0 commit comments

Comments
 (0)