// Create a comment
finalcomment=CommentModel.withTimestamp(fromUid:'user123',toUid:'admin456',comment:'This looks suspicious',isAdmin:false,);// Add to flag sub-collection
finalresult=awaitFlagCommentsService.addComment(flagId:'flag_abc123',comment:comment,);print('Comment added: ${result?.comment}');
Real-time Comment Stream
// Listen to all comments for a flag
finalstream=FlagCommentsService.getCommentsStream(flagId:'flag_abc123',limit:50,);stream.listen((comments){print('Flag has ${comments.length} comments');for(finalcommentincomments){print('- ${comment.comment} (${comment.isAdmin?'Admin':'User'})');}});
Flag Updates Stream
// Listen to flag changes (including comment count updates)
finalflagStream=FlagCommentsService.getFlagWithCommentsStream(flagId:'flag_abc123',);flagStream.listen((flag){if(flag!=null){print('Flag comment count: ${flag.commentCount}');print('Flag status: ${flag.status}');}});
Getting Comments
// Get all comments (paginated)
finalcomments=awaitFlagCommentsService.getComments(flagId:'flag_abc123',limit:20,);print('Retrieved ${comments.length} comments');