Package selection guidance compiled from public package information, community data, and project usage.
The string_similarity package calculates the degree of similarity between two strings using Dice's Coefficient, a method often more accurate and faster than Levenshtein distance. It is ideal for tasks like fuzzy matching, typo correction, and duplicate detection in text data. The algorithm evaluates shared bigrams between strings to produce a similarity score from 0 (no match) to 1 (exact match). This lightweight utility supports all major platforms including Android, iOS, Web, macOS, Windows, and Linux, making it versatile for cross-platform applications requiring efficient string comparison.
Use cases
Fuzzy search in user input
Detecting near-duplicate text entries
Auto-correct suggestions
Data deduplication
Matching product names across sources
Spelling correction
Key features
Uses Dice's Coefficient for accuracy
Fast performance compared to Levenshtein
Cross-platform compatibility
Simple API with clear similarity scores
Handles case-insensitive comparisons
Supports non-English characters
Suitable for
Text processing apps
Search and autocomplete features
Data cleaning workflows
User-facing input validation
Applications needing fast string matching
Considerations
Best for short to medium-length strings
Not optimized for very long texts
Does not support partial word matching
Limited to string-to-string comparison
No built-in handling of stopwords or stemming
Original README
Original README snapshot from the linked source repository. Visit the repository for the latest content.
string_similarity
A fast, dependency-free Dart package for measuring the similarity between two
strings with the Sørensen–Dice coefficient.
Use it for fuzzy search, spelling suggestions, duplicate detection, and ranking
the closest match from a list.
✨ Why string_similarity?
Simple extension methods and static methods
Scores from 0.0 (completely different) to 1.0 (identical)
Best-match search with individual ratings and the winning index
No runtime dependencies
Works on every platform supported by Dart and Flutter
final score = 'healed'.similarityTo('sealed');
print(score); // 0.8
The equivalent static method is:
final score = StringSimilarity.compareTwoStrings('healed', 'sealed');
🏆 Find the best match
final result = 'healed'.bestMatch([
'edward',
'sealed',
'theatre',
]);
print(result.bestMatch.target); // sealedprint(result.bestMatch.rating); // 0.8print(result.bestMatchIndex); // 1
Every candidate and its score remain available in result.ratings.
The equivalent static method is:
final result = StringSimilarity.findBestMatch(
'healed',
['edward', 'sealed', 'theatre'],
);
🧠 How it works
The package compares adjacent character pairs (bigrams) using the
Sørensen–Dice coefficient.
Whitespace is removed before comparison. Letter case and diacritics are kept,
so Cote, cote, and côte are different values.
🔡 Case-insensitive comparison
Normalize both strings before comparing them:
final score = 'DART'.toLowerCase().similarityTo('dart'.toLowerCase());
print(score); // 1.0
🧩 Available methods
API
Returns
Description
value.similarityTo(other)
double
Compares two nullable strings.
value.bestMatch(targets)
BestMatch
Rates every nullable target and selects the best one.
StringSimilarity.compareTwoStrings(first, second)
double
Static alternative to similarityTo.
StringSimilarity.findBestMatch(value, targets)
BestMatch
Static alternative to bestMatch.
BestMatch provides:
ratings: every target and its score
bestMatch: the highest-rated target
bestMatchIndex: the winning target's original index
⚙️ Behavior and edge cases
Input
Result
Two identical values, including null or ''
1.0
Only one value is null or empty
0.0
Different values where either has fewer than two characters
0.0
Several targets share the highest score
The first one wins
The target list is empty
Throws ArgumentError
🔎 Comparison details
Whitespace is ignored, but punctuation is not.
Comparison is case-sensitive and diacritic-sensitive.
The algorithm works on UTF-16 code units rather than grapheme clusters, so
some emoji and combined Unicode characters may not behave like visible
characters.
Sørensen–Dice measures shared bigrams. It is not a drop-in replacement for
edit-distance algorithms such as Levenshtein distance.