fayeed / flutter_mentions

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

Accessing a list of ids that were added as mentions? #23

Closed mlars84 closed 4 years ago

mlars84 commented 4 years ago

Hey @fayeed! Thanks so much for this tool. It works quite well for my needs aside from one issue... If I want to store the mentioned users by their id's, how can I get just a list of id's from the AnnotationEditingController or elsewhere? Currently the only way I seem to be able to access them is either in a string value or the markupText that spits out something like this:

Hey @[__aae73391-e9c9-4ca1-82cc-f5cb9f467415__](fayeed) and @[__807186f5-87e7-499f-84e2-9e290db65b90__](__mlars__)!

It seems less than ideal to have to parse through the markupText to extract the id's, so is there another way that I'm missing or is it really just a matter of parsing them? It seems like this could work a lot like how a multi-select would work where you would have a list of multiple selected id's. Thanks!

mlars84 commented 4 years ago

Ps, in the meantime I am doing this:

RegExp exp = new RegExp(r"@\[__(.*?)__\]");
String str = _formKey.currentState.controller.markupText;
Iterable<RegExpMatch> matches = exp.allMatches(str);
if (matches.length > 0) {
  matches.forEach((match) {
    mentions.add(match.group(1));
  });
}

This as I mentioned, is less-than-ideal but does in fact work.

fayeed commented 4 years ago

@mlars84 The reason this is not part of the package is that people can change the markup for the mentions that has a custom markup, because of that keeping a list of mentions on the controller because difficult to manage.