搜索插件、代码仓与 APP 分类

插件详情v5.0.0

linkify

Dart 中的低级别链接(文本、URL、电子邮件、电话号码、用户标签)解析库。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
39万
喜欢数
182
Pub 分数
150

安装插件

flutter pub add linkify

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Linkify 是一个低级别的 Dart 库,旨在解析文本并识别链接、URL、电子邮件地址、电话号码和用户标签。它提供了一种轻量且高效的方式,可在多个平台上从纯文本中检测和提取结构化数据。非常适合需要自动化文本处理的应用程序,如聊天界面、社交媒体动态或内容渲染。该库支持 Android、iOS、Web、macOS、Windows 和 Linux,确保广泛的兼容性。它不包含 UI 组件,而是专注于准确的解析,因此适合集成到自定义控件或文本处理器中。

适合场景

  • 解析用户生成的内容
  • 从文本中提取网址和电子邮件
  • 构建聊天或消息应用
  • 通过可点击链接增强文本显示
  • 处理社交媒体帖子
  • 自动化联系信息提取

主要特点

  • 支持 URL、电子邮件、电话号码和用户标签
  • 跨平台兼容性
  • 轻量且高效的解析
  • 无内置 UI 组件
  • 高精度的模式检测
  • 可扩展以支持自定义链接类型

适合对象

  • 开发文本密集型应用的开发者
  • 需要自动链接检测的应用程序
  • 自定义文本处理管道
  • 聊天或论坛应用
  • 内容渲染系统

使用建议

  • 不提供链接的视觉渲染
  • 需要手动实现点击处理
  • 限于基本文本模式
  • 不适用于复杂的HTML解析
  • 无内置样式选项
  • 依赖外部逻辑进行交互

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

linkify pub package

Low-level link (text, URLs, emails, phone numbers, user tags) parsing library in Dart.

Required Dart >=2.12 (has null-safety support).

Flutter library.

Pub - API Docs - GitHub

Install

Install by adding this package to your pubspec.yaml:

dependencies:
  linkify: ^5.0.0

Usage

import 'package:linkify/linkify.dart';

linkify("Made by https://cretezy.com person@example.com");
// Output: [TextElement: 'Made by ', UrlElement: 'https://cretezy.com' (cretezy.com), TextElement: ' ', EmailElement: 'person@example.com' (person@example.com)]
Options

You can pass LinkifyOptions to the linkify method to change the humanization of URLs (turning https://example.com to example.com):

linkify("https://cretezy.com");
// [UrlElement: 'https://cretezy.com' (cretezy.com)]

linkify("https://cretezy.com", options: LinkifyOptions(humanize: false));
// [UrlElement: 'https://cretezy.com' (https://cretezy.com)]
  • humanize: Removes http/https from shown URLs
  • removeWww: Removes www. from shown URLs
  • looseUrl: Enables loose URL parsing (should parse most URLs such as abc.com/xyz)
    • defaultToHttps: When used with [looseUrl], default to https instead of http
  • excludeLastPeriod: Excludes . at end of URLs
Linkifiers

You can pass linkifiers to linkify as such:

linkify("@cretezy", linkifiers: [UserTagLinkifier()]);

Available linkifiers:

  • EmailLinkifier
  • UrlLinkifier
  • PhoneNumberLinkifier
  • UserTagLinkifier

Custom Linkifier

You can write custom linkifiers for phone numbers or other types of links. Look at the URL linkifier for an example.

This is the flow:

  • Calls parse in the linkifier with a list of LinkifyElement. This starts as [TextElement(text)]
  • Your parsers then splits each element into it's parts. For example, [TextElement("Hello https://example.com")] would become [TextElement("Hello "), UrlElement("https://example.com")]
  • Each parsers is ran in order of how they are passed to the main linkify function. By default, this is URL and email linkifiers

所属分类

源码仓库

使用此插件的项目