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({
|
2021-03-15 15:39:44 +00:00
|
|
|
required String text,
|
|
|
|
required VoidCallback onTap,
|
|
|
|
TextStyle? style,
|
|
|
|
}) : 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
|
|
|
);
|
|
|
|
|
|
|
|
static link({
|
2021-03-15 15:39:44 +00:00
|
|
|
required String text,
|
|
|
|
String? urlString,
|
|
|
|
TextStyle? style,
|
2020-11-30 10:03:55 +00:00
|
|
|
}) =>
|
|
|
|
BrandSpanButton(
|
|
|
|
text: text,
|
|
|
|
style: style,
|
|
|
|
onTap: () => _launchURL(urlString ?? text),
|
|
|
|
);
|
|
|
|
|
|
|
|
static _launchURL(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';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|