fayeed / flutter_mentions

A simple flutter input widget to add @ mentions functionality to your app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to delete user from mention list after mention them for duplicate case like zalo,fb?

quocviet1996 opened this issue · comments

I wanna ask like fb, when user A is mentioned, then we can't mention duplicate A. So how to implement such a function? Thanks
I'm trying to delete user mention has been chosen on onSearchChanged, but after that an user mention before has been remove from markup too. You can see this in my attach image
image

     onSearchChanged:
                                  (String trigger, String value) {
                                if (trigger == "@") {
                                  if (_debounce?.isActive ?? false)
                                    _debounce!.cancel();
                                  _debounce = Timer(
                                      const Duration(milliseconds: 200),
                                      () {
                                    setState(() {
                                      mentiondata.clear();

                                      final List<Map<String, dynamic>>
                                          mentionTemp = [];
                                      mentionTemp.addAll([
                                        {
                                          "id": "3",
                                          "display": "fayeedP",
                                          "photo":
                                              "https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg"
                                        },
                                        {
                                          "id": "5",
                                          "display": "khaled",
                                          "photo":
                                              "https://images.pexels.com/photos/220453/pexels-photo-220453.jpeg",
                                        },
                                      ]);
                                      String text = _bloc.key.currentState!
                                          .controller!.markupText;
                                      RegExp regex = RegExp(
                                          r"@\[\__([a-zA-Z0-9]+)__\]");

                                      Iterable<Match> matches =
                                          regex.allMatches(text);
                                      List<String> results = [];

                                      for (Match match in matches) {
                                        results.add(match.group(1)!);
                                      }
                                      results.forEach((item) {
                                        mentionTemp.removeWhere((element) =>
                                            element['id'] == item);
                                      });
                                      mentiondata = mentionTemp;
                                    });
                                  });
                                }
                              },