mirror of
https://github.com/git-touch/git-touch
synced 2024-12-16 18:28:51 +01:00
feat: handle markdown link tap
This commit is contained in:
parent
250b520662
commit
b119a425cd
@ -27,6 +27,7 @@ class CreditsScreen extends StatelessWidget {
|
||||
Tuple2('provider', 'rrousselGit/provider'),
|
||||
Tuple2('filesize', 'synw/filesize'),
|
||||
Tuple2('tuple', 'dart-lang/tuple'),
|
||||
Tuple2('uri', 'google/uri.dart'),
|
||||
];
|
||||
|
||||
static const fonts = [
|
||||
|
@ -1,7 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/screens/issue.dart';
|
||||
import 'package:git_touch/screens/repository.dart';
|
||||
import 'package:git_touch/screens/user.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:primer/primer.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:uri/uri.dart';
|
||||
|
||||
class MarkdownView extends StatelessWidget {
|
||||
final String text;
|
||||
@ -14,9 +20,57 @@ class MarkdownView extends StatelessWidget {
|
||||
static final _hStyle =
|
||||
_basicStyle.copyWith(fontWeight: FontWeight.w600, height: 1.25);
|
||||
|
||||
Map<String, String> matchPattern(String url, String pattern) {
|
||||
var uri = Uri.parse(url);
|
||||
return UriParser(UriTemplate(pattern)).match(uri)?.parameters;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MarkdownBody(
|
||||
onTapLink: (url) {
|
||||
// TODO: Relative paths
|
||||
if (url.startsWith('https://github.com')) {
|
||||
Map<String, String> m;
|
||||
|
||||
m = matchPattern(url, '/{owner}/{name}/pull/{number}');
|
||||
if (m != null) {
|
||||
return Provider.of<ThemeModel>(context).pushRoute(
|
||||
context,
|
||||
(_) => IssueScreen(
|
||||
owner: m['owner'],
|
||||
name: m['name'],
|
||||
number: int.parse(m['number']),
|
||||
isPullRequest: true,
|
||||
));
|
||||
}
|
||||
|
||||
m = matchPattern(url, '/{owner}/{name}/issues/{number}');
|
||||
if (m != null) {
|
||||
return Provider.of<ThemeModel>(context).pushRoute(
|
||||
context,
|
||||
(_) => IssueScreen(
|
||||
owner: m['owner'],
|
||||
name: m['name'],
|
||||
number: int.parse(m['number']),
|
||||
));
|
||||
}
|
||||
|
||||
m = matchPattern(url, '/{owner}/{name}');
|
||||
if (m != null) {
|
||||
return Provider.of<ThemeModel>(context).pushRoute(
|
||||
context, (_) => RepositoryScreen(m['owner'], m['name']));
|
||||
}
|
||||
|
||||
m = matchPattern(url, '/{login}');
|
||||
if (m != null) {
|
||||
return Provider.of<ThemeModel>(context)
|
||||
.pushRoute(context, (_) => UserScreen(m['login']));
|
||||
}
|
||||
}
|
||||
|
||||
launchUrl(url);
|
||||
},
|
||||
data: text,
|
||||
styleSheet: MarkdownStyleSheet(
|
||||
a: _basicStyle.copyWith(color: PrimerColors.blue500),
|
||||
|
@ -34,6 +34,7 @@ dependencies:
|
||||
provider: ^3.1.0
|
||||
filesize: ^1.0.4
|
||||
tuple: ^1.0.2
|
||||
uri: ^0.11.3
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
|
Loading…
Reference in New Issue
Block a user