How to detect URLs and emails in a text in your Flutter app

Samuel Ezedi
2 min readApr 25, 2020

Hey there! I hope you’re doing great?, So I was building a chat application and I wanted to detect when users post links so that users of the app can tap the link which then opens in the browser. So I went in search of plugins in pub.dev and found just one that fits the need. After installation, I discovered it wasn’t working really great for me and wasn’t what I wanted here’s what I got:

This wasn’t good enough, the links weren’t completely detected and when tapped it may open in the browser, and then you have a broken link.

Deeply bothered by this, I finally came up with a plan to solve my problem. I decided to create my own URL and email detector which I called LinkWell. Here’s a look at how mine works

This gets the job done.

I have added this solution to pub.dev for anyone to use, to get it simply follow this link,

pub.dev/packages/linkwell

You will find every necessary information on how you can install LinkWell, but just a little information for basic usage

dependencies:  linkwell: ^0.1.9

run

flutter pub get

then import the library into your project file

import ‘package:linkwell/linkwell.dart’;

Usage

LinkWell( “Hi, my name is Samuel E. here’s my email: samuelezedi@gmail.com and website: samuelezedi.com”);

Well, I hope this solves your link detection problems in strings.

If you have any issues, you can always reach me at samuelzedi@gmail.com

or follow me on twitter: https://twitter.com/samuelezedi

Take good care.

--

--