0

I want to remove duplicate items but didnt found any method

List items = data
            .where((test) =>
                test["title"].toLowerCase().contains(query.toLowerCase()) ||
                test["ingredients"].toLowerCase().contains(query.toLowerCase()) ||
                test["keywords"].toLowerCase().contains(query.toLowerCase()) ||
                test["author"].toLowerCase().contains(query.toLowerCase())).toSet()
            .toList();

here is the output with duplication

[{ingredients:plus extra for rolling out (we like Wrights), keywords: Bread, author: Good Food, title: Spicy pizza, recipe_ID: 28}, {ingredients: plus extra for rolling out (we like Wrights), keywords: Indian, author: Good Food, title: Spicy pizza, recipe_ID: 28}, {ingredients:plus extra for rolling out (we like Wrights), keywords: Midweek, author: Good Food, title: Spicy pizza, recipe_ID: 28}]

so i want to remove these duplicate items,is there any method like distinct?

julemand101
  • 28,470
  • 5
  • 52
  • 48
Sanwal Ijaz
  • 154
  • 1
  • 11

1 Answers1

0

Check this SO thread. For your case:

var items = [
  test["title"],
  test["ingredients"],
  test["keywords"],
  test["author"]
]

var distinctItems = items.toSet().toList();

NOTE: Above I have created the list statically for simplicity. You should created it dynamically. If you dont want to distinguish between small and capital letters, that also you will have to take care.

Community
  • 1
  • 1
Sisir
  • 4,584
  • 4
  • 26
  • 37