From ccfbc0188c7ddb9c3aadae4184bbb2ad57ed0521 Mon Sep 17 00:00:00 2001 From: krawieck Date: Wed, 9 Sep 2020 20:52:31 +0200 Subject: [PATCH] Little tweaks --- lib/widgets/post.dart | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/widgets/post.dart b/lib/widgets/post.dart index f5e6c7e..80b425a 100644 --- a/lib/widgets/post.dart +++ b/lib/widgets/post.dart @@ -33,12 +33,7 @@ class Post extends StatelessWidget { final String instanceUrl; final bool fullPost; - /// nullable - final String postUrlDomain; - - Post(this.post, {this.fullPost = false}) - : instanceUrl = post.instanceUrl, - postUrlDomain = post.url != null ? post.url.split('/')[2] : null; + Post(this.post, {this.fullPost = false}) : instanceUrl = post.instanceUrl; // == ACTIONS == @@ -73,6 +68,14 @@ class Post extends StatelessWidget { Widget build(BuildContext context) { final theme = Theme.of(context); + final urlDomain = () { + if (post.url == null) return null; + + var url = post.url.split('/')[2]; + if (url.startsWith('www.')) return url.substring(4); + return url; + }(); + // TODO: add NSFW, locked, removed, deleted, stickied /// assemble info section Widget info() => Column(children: [ @@ -171,8 +174,8 @@ class Post extends StatelessWidget { TextSpan( text: 'NSFW', style: TextStyle(color: Colors.red)), - if (postUrlDomain != null) - TextSpan(text: ' · $postUrlDomain'), + if (urlDomain != null) + TextSpan(text: ' · $urlDomain'), if (post.removed) TextSpan(text: ' · REMOVED'), if (post.deleted) TextSpan(text: ' · DELETED'), ], @@ -200,7 +203,8 @@ class Post extends StatelessWidget { padding: const EdgeInsets.only(left: 10, right: 10, bottom: 10), child: Row( children: [ - Flexible( + Expanded( + flex: 100, child: Text( '${post.name}', textAlign: TextAlign.left, @@ -210,11 +214,8 @@ class Post extends StatelessWidget { ), if (post.url != null && whatType(post.url) == MediaType.other && - post.thumbnailUrl != null) + post.thumbnailUrl != null) ...[ Spacer(), - if (post.url != null && - whatType(post.url) == MediaType.other && - post.thumbnailUrl != null) InkWell( onTap: _openLink, child: Stack(children: [ @@ -238,6 +239,7 @@ class Post extends StatelessWidget { ) ]), ) + ] ], ), ); @@ -246,11 +248,6 @@ class Post extends StatelessWidget { Widget linkPreview() { assert(post.url != null); - var url = post.url.split('/')[2]; - if (url.startsWith('www.')) { - url = url.substring(4); - } - return Padding( padding: const EdgeInsets.all(10), child: InkWell( @@ -267,7 +264,7 @@ class Post extends StatelessWidget { children: [ Row(children: [ Spacer(), - Text('$url ', + Text('$urlDomain ', style: theme.textTheme.caption .apply(fontStyle: FontStyle.italic)), Icon(Icons.launch, size: 12),