Home > other >  How I make a unique list without any duplication value using RxList in Dart or Flutter?
How I make a unique list without any duplication value using RxList in Dart or Flutter?

Time:12-25

How do I make a unique list without any duplication value using RxList in Dart or Flutter?

My expectation:

RxList<String> myList = ["Canada", "India", "Canada"];

print(myList); 
// My expectation: ["Canada", "India"];

CodePudding user response:

You can use the Set to remove duplicates on your RxList which it's values a List:

RxList<String> myList = ["Canada", "India", "Canada"];

print(myList.value.toSet().toList()); // ["Canada","India"];

CodePudding user response:

I found two best way to filter duplication..

First one:
RxList<String> myList = ["Canada", "India", "Canada"].obs;
print(myList.value.toSet().toList()); // ["Canada", "India"]

Second one:
if(!myList.contain(value)){
myList.add(value);
}
  • Related