Cretezy / flutter_linkify

Turns text URLs and emails into clickable inline links in text for Flutter
https://pub.dartlang.org/packages/flutter_linkify
MIT License
263 stars 99 forks source link

[Feature Request] Custom linkStyles for different LinkifyElements #87

Open VictorUvarov opened 3 years ago

VictorUvarov commented 3 years ago

What are your thoughts about custom linkStyles for different LinkifyElements?

I'm imagining something a twitter/facebook post with hashtags, @usernames, links, etc... e.g. hello @username check out this link at https://www.link.com #stuff

Cretezy commented 3 years ago

If you can propose a clean design to implement this, I'm all for it. Let's try to keep the complexity to a minimum if possible.

VictorUvarov commented 3 years ago

I was thinking that maybe the Linkify widget would have a parameter that is a function instead of a TextStyle.

Probably a type like:

final TextStyle? Function(LinkableElement element) linkStyle;

that defaults to something like

Linkify({
   this.linkStyle = (element) => TextStyle(color: Colors.blue)
})

that way the user can do something like

Linkify(
  style: (LinkableElement element) {
    if (element is HashtagElement) {
      return Theme.of(context).textTheme.bodyText1?.copyWith(fontStyle: FontStyle.italic);
    } else if (element is ... ) {
      ...
    }

    return Theme.of(context).textTheme.bodyText1?.copyWith(color: Colors.blue);
  }
)
b1acKr0se commented 2 years ago

Hello, any update on this? I think @VictorUvarov's approach is quite solid.

zakton5 commented 1 year ago

I'm pretty sure this repo is not maintained anymore, unfortunately. I went ahead and forked this repo because I needed this feature. In addition, I also added a similar onLinkTap callback to be able to handle custom LinkifyElements you may have created.

https://github.com/zakton5/flutter_linkify

Use the following in your pubspec file to use it.

flutter_linkify:
  git:
    url: https://github.com/zakton5/flutter_linkify.git
    ref: feature/custom-text-styles