While implementing a normal mention where a user has a unique "@Userhandle
" is quite easy, I've been struggling with implementing one where the mention text is a "@User Name
", with spaces and everything, and the main issue, names are not unique.
Example:
"I'm glad to announce @John Doe and @John Doe are appointed as the secretary of flutter committee."
Here when we need to replace the names with there corresponding IDs before calling the API. And knowing which "John Doe" is which is not possible from the text.
The format in which I want to send the text to Backend is:
"I'm glad to announce @{John Doe:aef123-af12-ef123} and @{John Doe:f123as-dff12-f1f3} are appointed as the secretary of flutter committee."
Tried using a Map to store the selected mentions and then appending them to the name of the text using the following code. But this will append same IDs to the final text.
String getTextIdMapped() {
return text.splitMapJoin(regex, onMatch: (Match m) {
if (m[0] != null) {
final String? key = valueInUserNameMap(m[0]);
if (key != null) {
return m[0]!.replaceAll("@${userNameMap[key]}", "@${userNameMap[key]}=<$key>");
} else {
return m[0]!;
}
}
return "";
});
}
Any suggestions?
I will try to come back with an answer with code but in the mean time consider not allowing spaces in usernames - many website, applications or anything that needs a specific id removes the ability to add spaces to such imported id of your data store (for instance usernames).
Here is what im trying to pass on to you
https://stackoverflow.com/questions/64239679/flutter-textfield-how-do-i-restrict-my-user-from-using-space-in-textfield-by#:~:text=Another%20option%20to%20disable%20the,to%20restrict%20the%20allowed%20characters.&text=We%20created%20a%20new%20class%20called%20NoSpaceFormatter%20that%20extends%20TextInputFormatter%20.