Last active
July 8, 2023 22:40
-
-
Save folaoluwafemi/7d2360b017cb593e93b008cc07828f6a to your computer and use it in GitHub Desktop.
A method for comparing queries in dart
This file contains hidden or 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
abstract final class UtilFunctions { | |
static bool compareQueries(String value, String query) { | |
final String formattedValue = value.trim().toLowerCase(); | |
final List<String> queryWords = query.split(' '); | |
if (queryWords.length == 1) { | |
return formattedValue.contains(query.trim().toLowerCase()); | |
} | |
bool hasMatch = false; | |
for (String queryWord in queryWords) { | |
hasMatch = formattedValue.contains(queryWord.trim().toLowerCase()); | |
if (hasMatch) return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment