Skip to content

Turns text URLs and emails into clickable inline links in text for Flutter

License

Notifications You must be signed in to change notification settings

vitor-gyant/flutter_linkify

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flutter_linkify pub package

Turns text URLs and emails into clickable inline links in text for Flutter.

Pub - API Docs - GitHub

Install

Install by adding this package to your pubspec.yaml:

dependencies:
  flutter_linkify: ^2.1.0

It is highly recommend that you also add a dependency on url_launcher to open links in the browser/OS.

Usage

Basic:

import 'package:flutter_linkify/flutter_linkify.dart';

Linkify(
  onOpen: (link) => print("Clicked ${link.url}!"),
  text: "Made by https://cretezy.com",
);

Styling

Add a style to non-links (yellow) or links (red), and open in browser using url_launcher:

import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:url_launcher/url_launcher.dart';

Linkify(
  onOpen: (link) async {
    if (await canLaunch(link.url)) {
        await launch(link.url);
      } else {
        throw 'Could not launch $link';
      }
  },
  text: "Made by https://cretezy.com",
  style: TextStyle(color: Colors.yellow),
  linkStyle: TextStyle(color: Colors.red),
);

Humanizing

Remove http:// or https:// from the start of the URL using humanize:

Linkify(
  text: "Made by https://cretezy.com",
  humanize: true,
);

Advance

In the onOpen callback, a LinkableElement is passed in. You can check if it is a LinkElement (URL) or EmailElement using is for custom handling.

You can enable parsing of only some link types using the linkTypes option. All are enabled by default.

Full example can be found at example/lib/main.dart.

Example Screenshot

About

Turns text URLs and emails into clickable inline links in text for Flutter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 100.0%