fix: could not open link without scheme

This commit is contained in:
Lucas.Xu 2022-08-22 18:16:15 +08:00
parent 886c1f00e5
commit 1cd9a77e00

View File

@ -277,7 +277,13 @@ class RichTextStyle {
if (href != null) {
return TapGestureRecognizer()
..onTap = () async {
await launchUrlString(href);
final uri = Uri.parse(href);
// url_launcher cannot open a link without scheme.
final newHref =
(uri.scheme.isNotEmpty ? href : 'http://$href').trim();
if (await canLaunchUrlString(newHref)) {
await launchUrlString(newHref);
}
};
}
return null;