DecoratorRule.url constructor

DecoratorRule.url({
  1. required TextStyle style,
  2. required dynamic onTap(
    1. String
    ),
  3. bool looseUrl = true,
  4. bool humanize = false,
  5. bool removeWww = false,
})

Implementation

factory DecoratorRule.url({
  required TextStyle style,
  required Function(String) onTap,
  bool looseUrl = true,
  bool humanize = false,
  bool removeWww = false,
}) {
  return DecoratorRule(
      style: style,
      regExp: CommonRegExp.url(
        looseUrl: looseUrl,
      ),
      onTap: (match) {
        String url = match;
        if (!match.startsWith("http://") && !match.startsWith("https://")) {
          url = "https://$url";
        }
        if (url.endsWith(".")) {
          url = url.substring(0, url.length - 1);
        }
        onTap(url);
      },
      transformMatch: (match) {
        if (humanize) {
          String url = match;
          url = url.replaceFirst(RegExp('https?://'), '');
          if (url.endsWith("/")) {
            url = url.substring(0, url.length - 1);
          }
          if (removeWww) {
            url = url.replaceFirst(RegExp(r'www\.'), '');
          }
          return url;
        }
        return match;
      });
}