From 34ef2f5789e5d246255b8ceca7c66befe46f6efc Mon Sep 17 00:00:00 2001 From: mikecoomber <58986130+mikecoomber@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:29:47 +0000 Subject: [PATCH] fix: Made comment and author text optional for ZdsComment (#50) --- lib/src/components/molecules/comment.dart | 40 ++++++++++++----------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/src/components/molecules/comment.dart b/lib/src/components/molecules/comment.dart index d896941..aca998c 100644 --- a/lib/src/components/molecules/comment.dart +++ b/lib/src/components/molecules/comment.dart @@ -8,8 +8,8 @@ import '../../../zds_flutter.dart'; class ZdsComment extends StatelessWidget { /// Constructs a [ZdsComment] widget. const ZdsComment({ - required this.comment, - required this.author, + this.author, + this.comment, this.isReply = false, this.avatar, this.timeStamp, @@ -31,7 +31,7 @@ class ZdsComment extends StatelessWidget { ); /// The comment text. - final String comment; + final String? comment; /// The avatar widget to display. /// Should be a [ZetaAvatar] @@ -41,7 +41,7 @@ class ZdsComment extends StatelessWidget { final String? timeStamp; /// The author of the comment. - final String author; + final String? author; /// Whether the comment is a reply. /// If this is true, the reply action will automatically be hidden. @@ -142,12 +142,13 @@ class ZdsComment extends StatelessWidget { padding: EdgeInsets.only(right: spacing.small), child: avatar, ), - Text( - author, - style: ZetaTextStyles.labelLarge.copyWith( - fontWeight: FontWeight.w500, + if (author != null) + Text( + author!, + style: ZetaTextStyles.labelLarge.copyWith( + fontWeight: FontWeight.w500, + ), ), - ), const Spacer(), if (timeStamp != null) Padding( @@ -160,17 +161,18 @@ class ZdsComment extends StatelessWidget { ], ), ), - Padding( - padding: EdgeInsets.only( - top: spacing.small, - left: spacing.minimum, - right: spacing.minimum, - ), - child: Text( - comment, - style: Theme.of(context).textTheme.bodyMedium, + if (comment != null) + Padding( + padding: EdgeInsets.only( + top: spacing.small, + left: spacing.minimum, + right: spacing.minimum, + ), + child: Text( + comment!, + style: Theme.of(context).textTheme.bodyMedium, + ), ), - ), if (attachment != null) Padding( padding: EdgeInsets.only(top: spacing.medium),