Created
November 23, 2023 07:11
-
-
Save KrzysztofLen/fde31977ea3bffa314c886b966712840 to your computer and use it in GitHub Desktop.
#10FlutterChallenges — Part 4: Filtering List by Matching IDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
int id; | |
String name; | |
User({required this.id, required this.name}); | |
} | |
List<User> usersList = [ | |
User(id: 1, name: "John"), | |
User(id: 2, name: "Alex"), | |
User(id: 3, name: "Barry"), | |
User(id: 4, name: "Michael"), | |
User(id: 5, name: "Alexandra"), | |
]; | |
final idsList = [1, 3]; | |
List<User> filteredUsers = userList.where((User user) { | |
return idsList.any((id) => id == user.id); | |
}).toList(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment