2020-11-30 10:03:55 +00:00
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:selfprivacy/config/brand_colors.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
|
|
|
|
class BrandSpanButton extends TextSpan {
|
|
|
|
BrandSpanButton({
|
2022-06-05 19:36:32 +00:00
|
|
|
required final String text,
|
|
|
|
required final VoidCallback onTap,
|
|
|
|
final TextStyle? style,
|
2021-03-15 15:39:44 +00:00
|
|
|
}) : super(
|
2020-11-30 10:03:55 +00:00
|
|
|
recognizer: TapGestureRecognizer()..onTap = onTap,
|
|
|
|
text: text,
|
2022-05-24 18:55:39 +00:00
|
|
|
style: (style ?? const TextStyle()).copyWith(color: BrandColors.blue),
|
2020-11-30 10:03:55 +00:00
|
|
|
);
|
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
BrandSpanButton.link({
|
2022-06-05 19:36:32 +00:00
|
|
|
required final String text,
|
|
|
|
final String? urlString,
|
|
|
|
final TextStyle? style,
|
2022-06-05 22:40:34 +00:00
|
|
|
}) : super(
|
|
|
|
recognizer: TapGestureRecognizer()
|
|
|
|
..onTap = () => _launchURL(urlString ?? text),
|
|
|
|
text: text,
|
|
|
|
style: (style ?? const TextStyle()).copyWith(color: BrandColors.blue),
|
|
|
|
);
|
2020-11-30 10:03:55 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
static Future<void> _launchURL(final String link) async {
|
2022-05-17 20:08:28 +00:00
|
|
|
if (await canLaunchUrl(Uri.parse(link))) {
|
|
|
|
await launchUrl(Uri.parse(link));
|
2020-11-30 10:03:55 +00:00
|
|
|
} else {
|
|
|
|
throw 'Could not launch $link';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|