How to remove duplicate elements from a list using lists in Dart / Flutter?

1,116

I hope this works. Also import 'dart:convert';

List two = 
  one.map((f) => f.toString()).toSet().toList()
  .map((f) => json.decode(f) as List<dynamic>).toList();
Share:
1,116
Admin
Author by

Admin

Updated on December 18, 2022

Comments

  • Admin
    Admin over 1 year

    How to remove duplicates from a list with lists in Dart / Flutter?

    .toSet().toList() doesn't work.

    For Example:

    List one = [
         [
            [6, 51],
            [2, 76]
         ],
         [
            [6, 51],
            [2, 76]
         ],
         [
            [5, 66],
            [4, 96]
         ]
    ]
    

    Would be:

    List two = [
         [
            [6, 51],
            [2, 76]
         ],
         [
            [5, 66],
            [4, 96]
         ]
    ]