linkfy_text
一个轻量级的 flutter 包,用于链接包含 URL、电子邮件和 # 的文本。

用法
要使用此软件包,请将 linkfy_text 添加到 pubspec.yaml 文件中的依赖项。
示例
// first import the package
import 'package:linkfy_text/linkify_text.dart';
Container(
child: LinkifyText(
"This text contains a url: https://flutterdart.cn",
linkStyle: TextStyle(color: Colors.blue, fontSize: 16),
onTap: (link) {
/// do stuff with `link`
},
);
)
默认情况下,上述代码片段将链接化字符串中的所有 URL,您可以选择要链接化的链接类型,方法是传递 linkTypes 参数。
Container(
child: LinkifyText(
"This text contains a url: https://flutterdart.cn and #flutter",
linkStyle: TextStyle(color: Colors.blue, fontSize: 16),
linkTypes: [LinkType.url, LinkType.hashtag]
onTap: (link) {
/// do stuff with `link` like
/// if(link.type == Linktype.url) launchUrl(link.value);
},
);
)
| 参数 | 默认值 | 描述 |
|---|---|---|
文本样式 |
空 |
应用于文本的样式 |
linkStyle |
空 |
应用于链接化文本的样式,默认为 textStyle。 |
linkTypes |
LinkType.url |
一个 LinkTypes 列表,用于覆盖要链接化的文本中的链接,可以是标签、电子邮件或 URL。 |
onTap |
空 |
按下链接时调用的带 Link 参数的回调函数 |