-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
text_link.dart
54 lines (49 loc) · 1.29 KB
/
text_link.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
49
50
51
52
53
54
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class TextLink extends StatelessWidget {
final String text;
final String url;
final VoidCallback? onTap;
const TextLink({
super.key,
required this.text,
required this.url,
this.onTap,
});
const TextLink.withoutLink({
super.key,
required this.text,
required this.onTap,
}) : url = '';
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 5),
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
children: [
TextSpan(
text: text,
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.blue,
decoration: TextDecoration.underline,
decorationColor: Colors.blue,
fontSize: 18,
),
recognizer: TapGestureRecognizer()..onTap = () => onTap != null ? onTap!() : _launchUrl(url),
),
],
),
),
);
}
Future<void> _launchUrl(String url) async {
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
}
}
}