linkify 2.0.3

linkify pub package

Low-level link (text, URLs, emails) parsing library in Dart.

Flutter library.

Pub - API Docs - GitHub

Install #

Install by adding this package to your pubspec.yaml:

dependencies:
  linkify: ^2.0.3

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)]

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

[2.0.3] - 2020-01-08

  • Fix more minor lint issues
  • Remove extra print

[2.0.2] - 2019-12-30

  • Fix minor lint issues

[2.0.1] - 2019-12-27

  • Export defaultLinkifiers

[2.0.0] - 2019-12-27

  • Change LinkTypes to Linkifier
    • Supports custom linkifiers
  • Change LinkElement to UrlElement to better reflect UrlLinkifier (link != URL)
  • Change humanize option to LinkifyOptions
  • Enabled humanize by default

[1.0.1] - 2019-03-23

  • Republish to fix maintenance score

[1.0.0] - 2019-03-23

  • Initial release

example/linkify_example.dart

import 'package:linkify/linkify.dart';

void main() {
  print(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)]
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  linkify: ^2.0.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:linkify/linkify.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
84
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
92
Learn more about scoring.

We analyzed this package on Feb 12, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
collection ^1.0.0
pedantic ^1.0.0
test ^1.0.0