linkify 5.0.0 copy "linkify: ^5.0.0" to clipboard
linkify: ^5.0.0 copied to clipboard

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

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
copied to clipboard

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)]
copied to clipboard

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)]
copied to clipboard
  • 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()]);
copied to clipboard

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
160
likes
160
points
274k
downloads

Publisher

verified publishercretezy.com

Weekly Downloads

2024.07.16 - 2025.01.28

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

Repository (GitHub)

Documentation

API reference

License

MIT (license)

More

Packages that depend on linkify