-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreal_hyperlinks.dart
48 lines (45 loc) · 1.47 KB
/
real_hyperlinks.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import 'package:flutter/material.dart';
import 'package:custom_text/custom_text.dart';
import 'package:url_launcher/link.dart';
class RealHyperlinksExample extends StatelessWidget {
const RealHyperlinksExample();
@override
Widget build(BuildContext context) {
const matchStyle = TextStyle(color: Colors.blue);
return CustomText(
'Please visit [pub.dev](https://pub.dev/packages/custom_text) or '
'[GitHub](https://github.com/kaboc/flutter_custom_text) for more '
'details of this package.',
definitions: [
SpanDefinition(
matcher: const LinkMatcher(),
builder: (element) {
return WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Link(
uri: Uri.parse(element.groups[1]!),
target: LinkTarget.blank,
builder: (context, openLink) {
return GestureDetector(
onTap: openLink,
child: Text(element.groups[0]!),
);
},
),
);
},
matchStyle: matchStyle,
hoverStyle: matchStyle.copyWith(
decoration: TextDecoration.underline,
),
mouseCursor: SystemMouseCursors.click,
onTap: (_) {
// no-op
// This callback is only necessary to make hoverStyle
// applied on tap on mobile devices.
},
),
],
);
}
}