搜尋套件、儲存庫與 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

所屬分類

原始碼儲存庫

使用此套件的專案