Dn-a / flutter_tags

With flutter tags you can create selectable or input tags that automatically adapt to the screen width

Home Page:https://pub.dartlang.org/packages/flutter_tags

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Maximum selection

hardikJoshi123 opened this issue · comments

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!

@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

` _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个标签!');
}
}`