Closed Amber916Young closed 1 month ago
There are two things here:
Firstly, FlutterTaggerController
works with text
and formattedText
. The text
is what's displayed in the TextField
. The formattedText
contains more information that the widget uses to identifies tags. So if you have text with tags already formatted and you want to append to it through the controller, you need to work with the formattedText
.
It'll look like this:
String formattedText = controller.formattedText;
controller.text = formattedText += '👍'; // adds 👍
// update text selection
controller.selection = TextSelection.fromPosition(TextPosition(offset: controller.text.length));
// then call formatTags on the controller to preserve formatting
controller.formatTags();
Secondly, you have just identified a bug in the library. Because if you follow the steps above, you still wouldn't be able to trigger a search (but you'll get formatting to work). I'll fix that shortly. However, it's important to note that entering a trigger character only activates the search. You have to enter another character after the trigger to actually begin the search. By that I mean:
String formattedText = controller.formattedText;
controller.text = formattedText += '#';
// adds #. this WILL NOT trigger search
// update text selection
controller.selection = TextSelection.fromPosition(TextPosition(offset: controller.text.length));
controller.text = formattedText += 'a';
// adds a. this WILL trigger search with query string 'a'
// update text selection
controller.selection = TextSelection.fromPosition(TextPosition(offset: controller.text.length));
// then call formatTags on the controller to preserve formatting
controller.formatTags();
@Amber916Young I've published v2.1.1
on pub.dev with the fix for the issue with triggering search.
Also updated the README to guide on how to do what you've pointed out.
Let me know if this fixes your issue.
@Amber916Young I've published
v2.1.1
on pub.dev with the fix for the issue with triggering search. Also updated the README to guide on how to do what you've pointed out.Let me know if this fixes your issue.
Thank you very much for your detailed response. I will ensure the search issue is updated in the new version😀
You're welcome!
And thanks for pointing that out. I'll be closing this now. Feel free to reopen if necessary.
If I add "#" when clicking a button, it cannot trigger the search function and will also change the text style. like, add an emoji also will change the format of the text