diff --git a/README.md b/README.md index 76d293d..633186d 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,23 @@ +# linkfy_text + A lightweight flutter package to linkify texts containing urls, emails and hashtags. - +![issues](https://img.shields.io/github/issues/Iamstanlee/linkfy_text)] +[![pub package](https://img.shields.io/pub/v/http.svg)](https://pub.dev/packages/linkfy_text) -## Using +![final](https://user-images.githubusercontent.com/43510799/104180838-2385fd80-5451-11eb-8506-1640b4ea829f.gif) + +## Usage ```dart // first import the package import 'package:linkfy_text/linkify_text.dart'; + LinkifyText( "This text contains a url: https://flutter.dev", linkStyle: TextStyle(color: Colors.blue, fontSize: 16), onTap: (link) { - // onTap is called when a link is pressed - print("${link.value}"); + /// do stuff with `link` }, ); ``` @@ -21,11 +26,13 @@ Be default, The above snippet would linkify all urls in the string, you can choo ```dart LinkifyText( - "This text contains an #hashtag", + "This text contains an #hashtag and a url", linkStyle: TextStyle(color: Colors.blue, fontSize: 16), - linkTypes: [LinkType.hashtag] + linkTypes: [LinkType.url, LinkType.hashtag] onTap: (link) { - print("${link.value}"); + /// do stuff with `link` }, ); ``` + + diff --git a/test/utils/regex_test.dart b/test/utils/regex_test.dart index e3724cf..b44b0b4 100644 --- a/test/utils/regex_test.dart +++ b/test/utils/regex_test.dart @@ -42,7 +42,7 @@ void main() { test("Should match all emails", () { _emails.forEach((e) { bool hasMatch = RegExp(emailRegExp).hasMatch(e); - expect(hasMatch, true); + expect(hasMatch, isTrue); }); }); @@ -50,25 +50,25 @@ void main() { List _emails = ["hello@world", "@js.com"]; _emails.forEach((e) { bool hasMatch = RegExp(emailRegExp).hasMatch(e); - expect(hasMatch, false); + expect(hasMatch, isFalse); }); }); test("Should match all urls", () { _urls.forEach((u) { bool hasMatch = RegExp(urlRegExp).hasMatch(u); - expect(hasMatch, true); + expect(hasMatch, isTrue); }); }); test("Should match all hashtags", () { _hashtags.forEach((h) { bool hasMatch = RegExp(hashtagRegExp).hasMatch(h); - expect(hasMatch, true); + expect(hasMatch, isTrue); }); }); - test("Should construct regex pattern from LinkTypes and match", () { + test("Should construct regex pattern from LinkTypes and match length", () { RegExp _urlRegExp = constructRegExpFromLinkType([LinkType.url]); RegExp _hashtagRegExp = constructRegExpFromLinkType([LinkType.hashTag]); RegExp _emailRegExp = constructRegExpFromLinkType([LinkType.email]);