fayeed / flutter_mentions

A simple flutter input widget to add @ mentions functionality to your app
MIT License
107 stars 122 forks source link

Unable to pre-fill field with formatted mentions #43

Closed robinwkurtz closed 3 years ago

robinwkurtz commented 3 years ago

Hello, thanks for the library!

When using defaultText, the field does not show the formatted mention(s) as expected but the markup text. I've assured that my mention's data has the user previously mentioned.

I've tried with a custommarkupBuilder and the default one.

Here you can see the defaultText not formatted, but that if I add a new mention it works as expected:

https://user-images.githubusercontent.com/4428953/112364675-29982600-8cad-11eb-8507-465f02c7dd25.mp4

Thanks

fayeed commented 3 years ago

@robinwkurtz you don't need to pass the markup text to defaultText, you can just pass the normalized text. The reason is the package maintains markup text as an internal data to keep track of the mentions present in the textfield.

andrepo commented 3 years ago

@fayeed I second @robinwkurtz 's point. What if I want to edit an existing text that already contains mentions? If I pass in the sanitized text to defaultText the previous mentions are lost. The AnnotationEditingController should support a setter for markuText

fayeed commented 3 years ago

@andrepo The markup text has nothing to do with how mentions are rendered it is there for the developer so that they can use it with some other package like flutter_parsed_text, internally when you type anything or the text property is updated we run a function that goes in the Mentions array and finds a match for the @____ keyword and renders the mentions, this also recreates the markupText every time.

Now, that you know how it works internally it's really simple to write a function that can take care of sanitizing the text. & give you a mentioned array. You could write a function that uses a regex to get the markup for mention then extract the id & the name and recreate a string only using the name. Also after you sanitize the string don't forget to pass in the mentions array with mentioned users.

I know this can be a little work on the developer side, but that's how it works right now.

ashut08 commented 2 years ago

@robinwkurtz @andrepo have you find any solution till now?

amr1tv1rd1 commented 2 years ago

@robinwkurtz @andrepo have you find any solution till now?

Looking for the same.

JosePabloGoni commented 1 year ago

@ashut08 @amr1tv1rd1 I was able to find a quick solution to the problem, if you put the initial text with the mentions as "@" and rebuild the screen, it takes all the mentions in the correct format "@ [id] (name__)". I hope it works for you.

amr1tv1rd1 commented 1 year ago

@ashut08 @amr1tv1rd1 I was able to find a quick solution to the problem, if you put the initial text with the mentions as "@__" and rebuild the screen, it takes all the mentions in the correct format "@ [id] (name)". I hope it works for you.

Can you explain it with a little code @JosePabloGoni ?