Skip to content

Instantly share code, notes, and snippets.

@KrzysztofLen
Created November 23, 2023 07:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save KrzysztofLen/fde31977ea3bffa314c886b966712840 to your computer and use it in GitHub Desktop.
#10FlutterChallenges — Part 4: Filtering List by Matching IDs
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