Change `urlLanucher` signature to include `instanceUrl`

This commit is contained in:
krawieck 2020-09-12 09:30:22 +02:00
parent 28bbe5b06f
commit 77d54016f3
7 changed files with 37 additions and 14 deletions

View File

@ -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(

View File

@ -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(),
],

View File

@ -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<List<CommunityView>> 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(

View File

@ -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),

View File

@ -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));
}
}();

View File

@ -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()}"),
],
),
)));

View File

@ -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(),
],
),