I am making some entries and now i want to fetch recent entries based on a field
Like i have list of available Games.. and now i want to fatch recent 3 unique games from last entries..and want to show this three games in top of list and all other remaining games in sorted a->z order….
here is my code
void main() {
List<String> allGames = [
'Football',
'Cricket',
'Tennis',
'Hockey',
'Baseball',
'Race',
'Swimming',
'Polo',
'Rugby',
'Puzzle',
'Soccer',
];
List<String> recentGames = [
'Football',
'Football',
'Cricket',
'Football',
'Soccer',
'Football',
'Football',
'Soccer',
'Cricket',
'Puzzle',
'Puzzle'
];
//1 )first of all i want only first 3 unique Games from recentGames
// List<String> recent3= Football Cricket Soccer
//2 ) now want to merge all remaining games with recent3 games
//like remainingGames=allGames-recent3 ,sorted in A-> Z
// remainingGames= BaseBall Hockey Polo Race Rugby Swimming Tennis
//3) merge recent3+ remainingGames
// resultGames=Football Cricket Soccer Baseball Hockey Polo Race Rugby Swimming Tennis;
List<String> resultGames = [];
// logic code
print(resultGames);
}
2
Answers
It looks like you’re trying to achieve the following steps:
recentGames
list.allGames
list and sort them alphabetically.Here’s the code to achieve this:
This code will give you the desired output where the first 3 unique recent games are followed by the remaining games in alphabetical order.
3