class NameInitials { static const unknown = '?'; } String getNameInitials(String name) { if (name.isEmpty) return NameInitials.unknown; // Split the name by whitespace. final words = name.trim().split(RegExp(r'\s+')); if (words.isEmpty) return NameInitials.unknown; // If there's only one word, return its first letter. if (words.length == 1) return words.first[0].toUpperCase(); // Otherwise, use the first letter of the first and last words. return (words.first[0] + words.last[0]).toUpperCase(); }