Stack Overflow community!
I'm working on a feature for a mobile app where users can swipe through a list of items (let's say books for the sake of example), and the app will match these items based on a set of user preferences (e.g., preferred genres). Each item has its own list of characteristics (in this case, genres), and I need to compare these against the user's preferences to find matches.
The core of my current implementation in Dart looks something like this:
void checkForMatch() {
if (preferredGenres != null) {
var preferredGenresKeys = HashSet<String>.from(
preferredGenres!.map((genre) => genre.genreKey)
);
remainingBooks?.removeWhere((book) {
bool allGenresMatch = true;
for (var genreKey in book.genresForBook) {
if (!preferredGenresKeys.contains(genreKey)) {
allGenresMatch = false;
break;
}
}
if (allGenresMatch) {
matchedBooksSet.add(book);
}
return allGenresMatch;
});
} }
This method is called every time a user swipes, but I'm encountering performance issues, especially when the list of items and preferences grow larger. The lag becomes noticeable, affecting the user experience.
Any insights, code snippets, or pointers to relevant resources would be greatly appreciated. Thank you in advance for your help!
You can use checkForMatch() function like this.