initials method

String initials()

Extracts initials from a full name.

Example: 'John Doe' → 'JD'

Implementation

String initials() {
  final cleaned = trim();
  if (cleaned.isEmpty) return '';

  return cleaned
      .split(RegExp(r'\s+'))
      .where((word) => word.isNotEmpty)
      .map((word) => word[0].toUpperCase())
      .join();
}