From 77d54016f364474fbb7d260efad2f9d287bd20ce Mon Sep 17 00:00:00 2001 From: krawieck Date: Sat, 12 Sep 2020 09:30:22 +0200 Subject: [PATCH] Change `urlLanucher` signature to include `instanceUrl` --- lib/pages/communities_list.dart | 5 ++++- lib/pages/community.dart | 3 ++- lib/pages/instance.dart | 20 +++++++++++++++----- lib/pages/users_list.dart | 6 +++++- lib/widgets/comment.dart | 4 +++- lib/widgets/markdown_text.dart | 8 +++++--- lib/widgets/post.dart | 5 +++-- 7 files changed, 37 insertions(+), 14 deletions(-) diff --git a/lib/pages/communities_list.dart b/lib/pages/communities_list.dart index ab1e0d9..e4dc958 100644 --- a/lib/pages/communities_list.dart +++ b/lib/pages/communities_list.dart @@ -31,7 +31,10 @@ class CommunitiesListPage extends StatelessWidget { subtitle: communities[i].description != null ? Opacity( opacity: 0.5, - child: MarkdownText(communities[i].description), + child: MarkdownText( + communities[i].description, + instanceUrl: communities[i].instanceUrl, + ), ) : null, onTap: () => goToCommunity.byId( diff --git a/lib/pages/community.dart b/lib/pages/community.dart index adafdc9..6b877fc 100644 --- a/lib/pages/community.dart +++ b/lib/pages/community.dart @@ -433,7 +433,8 @@ class _AboutTab extends StatelessWidget { if (community.description != null) ...[ Padding( padding: const EdgeInsets.symmetric(horizontal: 15), - child: MarkdownText(community.description), + child: MarkdownText(community.description, + instanceUrl: community.instanceUrl), ), _Divider(), ], diff --git a/lib/pages/instance.dart b/lib/pages/instance.dart index e9ee421..7d3f3a0 100644 --- a/lib/pages/instance.dart +++ b/lib/pages/instance.dart @@ -208,7 +208,9 @@ class InstancePage extends HookWidget { Center(child: Text('comments go here')), ], ), - _AboutTab(site, communitiesFuture: communitiesFuture), + _AboutTab(site, + communitiesFuture: communitiesFuture, + instanceUrl: instanceUrl), ], ), ), @@ -241,9 +243,12 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { class _AboutTab extends HookWidget { final FullSiteView site; final Future> communitiesFuture; + final String instanceUrl; - const _AboutTab(this.site, {@required this.communitiesFuture}) - : assert(communitiesFuture != null); + const _AboutTab(this.site, + {@required this.communitiesFuture, @required this.instanceUrl}) + : assert(communitiesFuture != null), + assert(instanceUrl != null); void goToUser(int id) { print('GO TO USER $id'); @@ -280,7 +285,10 @@ class _AboutTab extends HookWidget { children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 15), - child: MarkdownText(site.site.description), + child: MarkdownText( + site.site.description, + instanceUrl: instanceUrl, + ), ), _Divider(), SizedBox( @@ -356,7 +364,9 @@ class _AboutTab extends HookWidget { e.preferredUsername.isEmpty) ? '@${e.name}' : e.preferredUsername), - subtitle: e.bio != null ? MarkdownText(e.bio) : null, + subtitle: e.bio != null + ? MarkdownText(e.bio, instanceUrl: instanceUrl) + : null, onTap: () => goToUser(e.id), leading: e.avatar != null ? CachedNetworkImage( diff --git a/lib/pages/users_list.dart b/lib/pages/users_list.dart index f4ab17c..16b5259 100644 --- a/lib/pages/users_list.dart +++ b/lib/pages/users_list.dart @@ -2,6 +2,7 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:lemmy_api_client/lemmy_api_client.dart'; +import '../util/api_extensions.dart'; import '../widgets/markdown_text.dart'; class UsersListPage extends StatelessWidget { @@ -35,7 +36,10 @@ class UsersListPage extends StatelessWidget { subtitle: users[i].bio != null ? Opacity( opacity: 0.5, - child: MarkdownText(users[i].bio), + child: MarkdownText( + users[i].bio, + instanceUrl: users[i].instanceUrl, + ), ) : null, onTap: () => goToUser(context, users[i].id), diff --git a/lib/widgets/comment.dart b/lib/widgets/comment.dart index fa76395..1ae29d6 100644 --- a/lib/widgets/comment.dart +++ b/lib/widgets/comment.dart @@ -169,7 +169,9 @@ class Comment extends StatelessWidget { style: TextStyle(fontStyle: FontStyle.italic), )); } else { - return Flexible(child: MarkdownText(commentTree.comment.content)); + return Flexible( + child: MarkdownText(commentTree.comment.content, + instanceUrl: commentTree.comment.instanceUrl)); } }(); diff --git a/lib/widgets/markdown_text.dart b/lib/widgets/markdown_text.dart index ef0ebba..427294e 100644 --- a/lib/widgets/markdown_text.dart +++ b/lib/widgets/markdown_text.dart @@ -6,20 +6,22 @@ import 'package:markdown/markdown.dart' as md; import '../url_launcher.dart'; class MarkdownText extends StatelessWidget { + final String instanceUrl; final String text; - MarkdownText(this.text); + MarkdownText(this.text, {@required this.instanceUrl}) + : assert(instanceUrl != null); @override Widget build(BuildContext context) => MarkdownBody( data: text, extensionSet: md.ExtensionSet.gitHubWeb, onTapLink: (href) { - urlLauncher(context, href) + urlLauncher(context: context, url: href, instanceUrl: instanceUrl) .catchError((e) => Scaffold.of(context).showSnackBar(SnackBar( content: Row( children: [ Icon(Icons.warning), - Text("couldn't open link"), + Text("couldn't open link, ${e.toString()}"), ], ), ))); diff --git a/lib/widgets/post.dart b/lib/widgets/post.dart index 625da16..64c1935 100644 --- a/lib/widgets/post.dart +++ b/lib/widgets/post.dart @@ -144,7 +144,8 @@ class Post extends StatelessWidget { @override Widget build(BuildContext context) { final theme = Theme.of(context); - void _openLink() => urlLauncher(context, post.url); + void _openLink() => + urlLauncher(context: context, url: post.url, instanceUrl: instanceUrl); final urlDomain = () { if (post.url == null) return null; @@ -437,7 +438,7 @@ class Post extends StatelessWidget { if (post.body != null) Padding( padding: const EdgeInsets.all(10), - child: MarkdownText(post.body)), + child: MarkdownText(post.body, instanceUrl: instanceUrl)), actions(), ], ),