Thursday, March 28, 2024

How to highlight all the links in the text Flutter

LinkWell is a Text widget that highlight all the links

LinkWell is a Text widget that highlight all the links in the text which then navigates the user to the URL when tapped.LinkWell is Text Plugin that detects URLs and Emails in a String and when tapped opens in user browsers.

Installation

Run this command:

With Flutter:

 $ flutter pub add linkwell

This will add a line like this to your package’s pubspec.yaml (and run an implicit dart pub get):


dependencies:
  linkwell: ^2.0.6

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

Import it

Now in your Dart code, you can use:

import 'package:linkwell/linkwell.dart';

Usage

Basic:

LinkWell(
    "Hi here's my email: samuelezedi@gmail.com and website: https://samuelezedi.com"
);

Add Styling

To add style to links

LinkWell(
    "Hi here's my email: samuelezedi@gmail.com and website: https://samuelezedi.com",
    linkStyle: TextStyle(color: Colors.blue,fontSize: 17)
);

To add style to non links

LinkWell(
    "Hi here's my email: samuelezedi@gmail.com and website: https://samuelezedi.com",
    style: TextStyle(color: Colors.black,fontSize: 17)
);

Naming Links

If you would like to name the links

LinkWell(
    "By registering you agree to our samuelezedi.com/terms and samuelezedi.com/privacy",
    listOfNames: {
        'samuelezedi.com/terms' : 'Terms',
        'samuelezedi.com/privacy' : 'Privacy Policy'
    },
);

Demo

Basic Usage Named Links