Change if with 2 `Text`s to 1 `Text` with ternary inside

This commit is contained in:
krawieck 2020-08-30 19:31:55 +02:00
parent 91aada67e9
commit fcafde2d0f
1 changed files with 8 additions and 11 deletions

View File

@ -348,13 +348,10 @@ class PostWidget extends StatelessWidget {
child: Row( child: Row(
children: [ children: [
Icon(Icons.comment), Icon(Icons.comment),
if (post.numberOfComments == 1)
Text(' 1 comment')
else
Expanded( Expanded(
flex: 999, flex: 999,
child: Text( child: Text(
''' ${NumberFormat.compact().format(post.numberOfComments)} comments''', ''' ${NumberFormat.compact().format(post.numberOfComments)} comment${post.numberOfComments == 1 ? '' : 's'}''',
overflow: TextOverflow.fade, overflow: TextOverflow.fade,
softWrap: false, softWrap: false,
), ),
@ -370,7 +367,7 @@ class PostWidget extends StatelessWidget {
: Icon(Icons.bookmark_border), : Icon(Icons.bookmark_border),
onPressed: _savePost), onPressed: _savePost),
IconButton(icon: Icon(Icons.arrow_upward), onPressed: _upvotePost), IconButton(icon: Icon(Icons.arrow_upward), onPressed: _upvotePost),
Text(post.score.toString()), Text(NumberFormat.compact().format(post.score)),
IconButton( IconButton(
icon: Icon(Icons.arrow_downward), onPressed: _downvotePost), icon: Icon(Icons.arrow_downward), onPressed: _downvotePost),
], ],