flutter_linkify
![pub package](https://camo.githubusercontent.com/54b18237063182023629a2df5e64f9e70f35ec22d9878a31757720233dd4d676/68747470733a2f2f696d672e736869656c64732e696f2f7075622f762f666c75747465725f6c696e6b6966792e737667)
Turns text URLs and emails into clickable inline links in text for Flutter.
Install
Install by adding this package to your pubspec.yaml
:
dependencies:
flutter_linkify: ^3.1.3
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),
);
All RichText
options are available for use.
Linkify Options
By default, humanization (removal of http://
or https://
from the start of the URL) is enabled. You may disable it by passing options
:
Linkify(
text: "Made by https://cretezy.com",
options: LinkifyOptions(humanize: false),
);
Selectable Text
Use the SelectableLinkify
widget to create selectable text. All SelectableText
options are available for use.
SelectableLinkify(
text: "Made by https://cretezy.com\n\nMail: example@gmail.com",
);
Advance
In the onOpen
callback, a LinkableElement
is passed in.
You can check if it is a UrlElement
or EmailElement
using is
for custom handling.
You can enable parsing of only some link types using the linkifiers
option. URL and email are enabled by default.
Full example can be found at example/lib/main.dart
.