flutter_linkify icon indicating copy to clipboard operation
flutter_linkify copied to clipboard

[Feature Request] Custom linkStyles for different LinkifyElements

Open VictorUvarov opened this issue 3 years ago • 4 comments

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

VictorUvarov avatar May 04 '21 20:05 VictorUvarov

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.

Cretezy avatar May 13 '21 16:05 Cretezy

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);
  }
)

VictorUvarov avatar May 13 '21 18:05 VictorUvarov

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

b1acKr0se avatar Nov 22 '21 08:11 b1acKr0se

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

zakton5 avatar Feb 03 '23 00:02 zakton5