[Solved] Remove Common Elements from 2 Lists of List Flutter Dart

Manav Arora Asks: Remove Common Elements from 2 Lists of List<DateTime> Flutter Dart
I have these 2 list of Date Time:

Code:
 List l1 = ["2021-08-02 14:10:00.000, 2021-08-02 14:15:00.000"];
 List l2 = ["2021-08-02 13:40:00.000, 2021-08-02 13:45:00.000, 2021-08-02 13:50:00.000, 2021-08-02 13:55:00.000, 2021-08-02 14:00:00.000, 2021-08-02 14:05:00.000, 2021-08-02 14:10:00.000, 2021-08-02 14:15:00.000"];

I need to extract and remove the common elements between l1 and l2. I tried it using this method:

Code:
l2.removeWhere((element) => l1.contains(element));
print(l2);

But, it just gives null. Am I doing something wrong here?

I removed the (“”) and tried it in Dart Pad. There it seems to work just fine.

Dart Pad Code​

Code:
void main() {
List l1 = [2021-08-02 14:10:00.000, 2021-08-02 14:15:00.000];
List l2 = [2021-08-02 13:40:00.000, 2021-08-02 13:45:00.000, 2021-08-02 13:50:00.000, 
2021-08-02 13:55:00.000, 2021-08-02 14:00:00.000, 2021-08-02 14:05:00.000, 2021-08-02 
14:10:00.000, 2021-08-02 14:15:00.000];
l1.removeWhere((element)=> l2.contains(element));
print(l1);
}

Output​

Code:
[2021-08-02 14:10:00.000, 2021-08-02 14:15:00.000]

Can Anybody help me out here.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.