Dn-a/flutter_tags

Do not allow white spaces in the middle of a tag

FerBueroTrebino opened this issue · 2 comments

Hello, thanks for the Package, it is working great!

I need to create tags like hashtags with no spaces, I know how to trim the input of the user, but I would like to not allow the user to input a tag with white spaces in the middle, I think a way to achieve this is to fire onSubmitted when the user press the space bar.
Anyone can help me to achieve this? I've been looking for a solution with no results.

Thanks in advance,
Fer

Dn-a commented

Hi @FerBueroTrebino , you could do it using regular expressions RegExp. Something like this:


onSubmitted: (String str) {
    RegExp exp = new RegExp(r"^[a-zA-Z0-9_]*$");
   if(exp.allMatches(str) != null)
        setState(() {
          _items.add(str);
        });
},

Thanks @Dn-a for you help! I solved in this way:

onSubmitted: (String tag) {
businessProvider.addLabelTemp =
(tag.replaceAll(RegExp('[# ]'), ''));
},