Dn-a / flutter_tags

With flutter tags you can create selectable or input tags that automatically adapt to the screen width
https://pub.dartlang.org/packages/flutter_tags
MIT License
507 stars 127 forks source link

Do not allow white spaces in the middle of a tag #59

Closed FerBueroTrebino closed 3 years ago

FerBueroTrebino commented 4 years ago

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 4 years ago

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);
        });
},
FerBueroTrebino commented 4 years ago

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

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