Skip to content

Instantly share code, notes, and snippets.

@alphamikle
Created January 31, 2021 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphamikle/ca57f261efc058ebc963678d6ae05241 to your computer and use it in GitHub Desktop.
Save alphamikle/ca57f261efc058ebc963678d6ae05241 to your computer and use it in GitHub Desktop.
Filter items function
/// Depending on the set flag [USE_SIMILARITY]
/// whether or not search with string similarity is used
List<Item> filterItems(Packet2<List<Item>, String> itemsAndInputValue) {
return itemsAndInputValue.value.where((Item item) {
return item.profile.contains(itemsAndInputValue.value2) || (USE_SIMILARITY && isStringsSimilar(item.profile, itemsAndInputValue.value2));
}).toList();
}
bool isStringsSimilar(String first, String second) {
return max(StringSimilarity.compareTwoStrings(first, second), StringSimilarity.compareTwoStrings(second, first)) >= 0.3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment