Ad
How To Delete Duplicate Items From A List Dart | Flutter
I have a set of items. From this i want to delete all duplicate values. i tried this
finalList = [...{...users!}];
and this print(users.toSet().toList());
. But both are printing all the data in the list. It didn't removing duplicate values. Below is my list
List users = [
{
"userEmail":"[email protected]"
},
{
"userEmail":"[email protected]"
},
{
"userEmail":"[email protected]"
},
{
"userEmail":"[email protected]"
},
{
"userEmail":"[email protected]"
},
];
Expected Output
List users = [
{
"userEmail":"[email protected]"
},
{
"userEmail":"[email protected]"
},
{
"userEmail":"[email protected]"
},
];
Ad
Answer
Let's try, here you get the unique list
void main() {
var users = [
{"userEmail": "[email protected]"},
{"userEmail": "[email protected]"},
{"userEmail": "[email protected]"},
{"userEmail": "[email protected]"},
{"userEmail": "[email protected]"},
];
var uniqueList = users.map((o) => o["userEmail"]).toSet();
print(uniqueList.toList());
}
Ad
source: stackoverflow.com
Related Questions
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → Octobercms/Laravel get id based on relation
- → How do i get base url in OctoberCMS?
- → Eloquent Multitable query
- → ListView.DataSource looping data for React Native
- → Laravel File Listing & Counting by Filtered File Names
- → List class element(index).fadetoggle(some speed) not working
- → Using Array in '->where()' for Laravel Query Building
- → List of react-native StyleSheet properties and options
- → How to access a complex object comming from a datatable cell in JQuery/Javascript
- → getting the correct record in Angular with a json feed and passed data
- → CasperJS - NodeList.length return 0
- → Plugin with single item ( october cms )
Ad