flutter_linkify
flutter_linkify copied to clipboard
[Feature Request] Custom linkStyles for different LinkifyElements
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
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.
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);
}
)
Hello, any update on this? I think @VictorUvarov's approach is quite solid.
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 LinkifyElement
s 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