How can I parse and replace a word as a hashtag link when user types some text using flutter?
1,367
Assuming that you want to do this once the user has finished posting and not inside the typing bar:
The smart_text_view 0.1.0 package contains something called LinkTextSpan, which you can use to easily implement this on the view. Their example folder contains an example that was implemented.
As shown in the Flutter's Official Implementation here for the Flutter Gallery Drawyer, you can do this:
_LinkTextSpan(
style: linkStyle,
url: 'https://something.com',
text: 'flutter github repo',
),
and
_LinkTextSpan({ TextStyle style, String url, String text }) : super(
style: style,
text: text ?? url,
recognizer: TapGestureRecognizer()..onTap = () {
launch(url, forceSafariVC: false);
}
);
Author by
Dead Pool
Updated on December 10, 2022Comments
-
Dead Pool over 1 year
I want when a user types some text to make a post. But the thing is when the user types a hashtag (e.g. #avengers) I can parse and replace that hashtag with a link or ontap widget... Same goes with URL links
-
Phuc Tran about 5 yearsThe hashtag is in the TextField also? Or it is in the post?
-
Dead Pool about 5 yearsinside the textfield
-
Phuc Tran about 5 yearsCan you share the design of what you want?
-
Dead Pool about 5 years@PhucTran it works the same way like facebook, youtube and instagram's hashtag system
-
Dead Pool about 5 years@PhucTran I would show code but it's a lot
-
Shangari C almost 5 years@DeadPool Did you find the solution about mentions,HashTag.can you pls suggest related to that.
-
Shangari C almost 5 years@PhucTran Can you pls suggest an idea to implement mentions,hastags how to identify @,# to show popup list.
-
-
kilokahn over 4 yearsCan you elaborate a bit more about how this works - a snippet of code demonstrating how you would implement smart_text_view to parse hashtags will go a long way in helping me understand this better.