skip to Main Content

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"];

2

Answers


  1. Chosen as BEST ANSWER
    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);
    }
    

  2. 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"];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search