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
508 stars 124 forks source link

Maximum selection #51

Closed hardikJoshi123 closed 3 years ago

hardikJoshi123 commented 4 years ago

Hi, thank you for this awesome tags library. Is there any parameter for the maximum N number so user can not select more than given number of tags?

In our app, we are allowing user to select 3 interests from given 400 interests in popup. Once 3 tags get selected, how to load them with active states once popup shows again?

Thank you!

Dn-a commented 4 years ago

@hardikJoshi123 You will have to use an external list where you store the active tags, and in itembuilder carry out a check with the list of all the other elements. In the active parameter of ItemTags set true for the corresponding tag. You can get the active tags from ItemTags onPressed callback

buildnewapp commented 3 years ago

` _getAllItem(){ tags = []; List lst = _tagStateKey.currentState?.getAllItem; if(lst!=null) lst.where((a) => a.active==true).forEach( (a){ tags.add({'name':a.title, 'id':a.customData==null ? '0' : a.customData.toString()}); });

if (tags.length>3) { return showTip('最多选择3个标签!'); } }`