Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

A lightweight flutter package to linkify texts containing urls, emails and hashtags

linkfy_text

A lightweight flutter package that linkifies a text containing urls, emails and hashtag like twitter does.

Usage

To use this package, add linkfy_text as a dependency in your pubspec.yaml file.

Example:

// first import the package
import 'package:linkfy_text/linkify_text.dart';

Container(
    child: LinkifyText(
    "This text contains a url: https://flutter.dev",
    linkStyle: TextStyle(color: Colors.blue, fontSize: 16),
    onTap: (link) {
        /// do stuff with `link`
        },
    );
)

Be default, The above snippet would linkify all urls in the string, you can choose what type of link to linkify by passing the linkTypes parameter

Container(
    child: LinkifyText(
    "This text contains a url: https://flutter.dev and #flutter",
    linkStyle: TextStyle(color: Colors.blue, fontSize: 16),
    linkTypes: [LinkType.url, LinkType.hashtag]
    onTap: (link) {
        /// do stuff with `link` like
        /// if(link.type == Linktype.url) launchUrl(link.value);
        },
    );
)

API Reference

LinkfyText

ParameterTypeDescription
textStyleTextStylestyle applied to the text
linkStyleTextStylestyle applied to the linkified text. defaults to textStyle
linkTypesList<LinkType>a list of LinkType used to override the links to be linkified in a text either a url, hashtag or email. defaults to [LinkType.url]
onTapFunction(Link)function called when a link is pressed

Link

ParameterTypeDescription
typeLinkTypethe link type either url, email or hashtag
valueStringvalue this link holds

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don’t know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

TODO

Download linkfy text app source code on GitHub

Exit mobile version