endsWithAny method
Returns true if this string ends with any non-empty suffix in find.
Entries may be any length ('.dart', '👋', a single character).
Matching uses String.endsWith (UTF-16 code units). Empty entries never
match, so [''] does not make every string "end with" something.
Example:
'file.dart'.endsWithAny(<String>['.dart', '.txt']); // true
'Hi!'.endsWithAny(<String>['.', '!']); // true
'hi 👋'.endsWithAny(<String>['👋']); // true
'abc'.endsWithAny(<String>['']); // false
Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
bool endsWithAny(List<String> find) {
if (isEmpty || find.isEmpty) {
return false;
}
// Compare whole suffixes: the old code compared each entry with only the
// last grapheme, so any entry longer than one character never matched.
// Empty entries are skipped because endsWith('') is always true.
return find.any((String e) => e.isNotEmpty && endsWith(e));
}