[英]Open the link in the browser in flutter_linkify package
我使用這個 package 打開文本內的鏈接,但是這個 package 打開應用程序內的鏈接,我可以讓它在瀏覽器中打開鏈接嗎?
這是 package 鏈接: https://pub.dev/packages/flutter_linkify
您可以使用以下示例在瀏覽器中打開鏈接
Linkify(
onOpen: (link) async {
if (await canLaunch(link.url)) {
await launchUrl(Uri.parse(link.url),
mode: LaunchMode.externalApplication);
} else {
throw 'Could not launch $link';
}
},
text: "Made by https://cretezy.com",
style: TextStyle(color: Colors.yellow),
linkStyle: TextStyle(color: Colors.red),);
在flutter_linkify的 README 中清楚地寫道
強烈建議您還添加對url_launcher的依賴項以在瀏覽器/操作系統中打開鏈接。
安裝
通過將此 package 添加到您的pubspec.yaml:
dependencies:
flutter_linkify: ^5.0.2
強烈建議您還添加對 url_launcher 的依賴項以在瀏覽器/操作系統中打開鏈接。
為非鏈接(黃色)或鏈接(紅色)添加樣式,並使用url_launcher 在瀏覽器中打開:
import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:url_launcher/url_launcher.dart';
Linkify(
onOpen: (link) async {
if (await canLaunch(link.url)) {
await launch(link.url);
} else {
throw 'Could not launch $link';
}
},
text: "Made by https://cretezy.com",
style: TextStyle(color: Colors.yellow),
linkStyle: TextStyle(color: Colors.red),
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.