From f44c0f60a53bb1370e00b75b39a87257ad16f17b Mon Sep 17 00:00:00 2001 From: krawieck Date: Tue, 1 Sep 2020 14:17:56 +0200 Subject: [PATCH] change some expressions to IIFEs --- lib/widgets/comment.dart | 49 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/widgets/comment.dart b/lib/widgets/comment.dart index be479bc..7a3ea1e 100644 --- a/lib/widgets/comment.dart +++ b/lib/widgets/comment.dart @@ -25,30 +25,33 @@ class Comment extends StatelessWidget { var comment = commentTree.comment; // decide which username to use - var username; - if (comment.creatorPreferredUsername != null && - comment.creatorPreferredUsername != '') { - username = comment.creatorPreferredUsername; - } else { - username = '@${comment.creatorName}'; - } + final username = () { + if (comment.creatorPreferredUsername != null && + comment.creatorPreferredUsername != '') { + return comment.creatorPreferredUsername; + } else { + return '@${comment.creatorName}'; + } + }(); + + final body = () { + if (comment.deleted) { + return Flexible( + child: Text( + 'comment deleted by creator', + style: TextStyle(fontStyle: FontStyle.italic), + )); + } else if (comment.removed) { + return Flexible( + child: Text( + 'comment deleted by moderator', + style: TextStyle(fontStyle: FontStyle.italic), + )); + } else { + return Flexible(child: MarkdownText(commentTree.comment.content)); + } + }(); - var body; - if (comment.deleted) { - body = Flexible( - child: Text( - 'comment deleted by creator', - style: TextStyle(fontStyle: FontStyle.italic), - )); - } else if (comment.removed) { - body = Flexible( - child: Text( - 'comment deleted by moderator', - style: TextStyle(fontStyle: FontStyle.italic), - )); - } else { - body = Flexible(child: MarkdownText(commentTree.comment.content)); - } return Column( children: [ Container(