toAvatarInitials method

String toAvatarInitials()

Extracts initials from a name (e.g., "Jane Doe" → "JD").

Takes the first letter of the first two words.

Implementation

String toAvatarInitials() {
  final words = trim().split(RegExp(r'\s+'));
  if (words.isEmpty) return '';
  if (words.length == 1) {
    return words.first.isNotEmpty ? words.first[0].toUpperCase() : '';
  }
  return '${words.first[0]}${words.last[0]}'.toUpperCase();
}