words method
Splits the string into a list of words, using space (" ") as the delimiter.
This method splits the string by spaces, and filters out any empty or null words.
Implementation
List<String>? words() {
// Handle empty string case by returning null.
if (isEmpty) {
return null;
}
// Split by space, convert empty parts to null, then filter out the nulls.
return split(
' ',
).map((String word) => word.nullIfEmpty()).whereType<String>().toList().nullIfEmpty();
}