initials static method

String initials(
  1. String name
)

Up to two initials: "Ada Lovelace" -> "AL".

Implementation

static String initials(String name) {
  final words = name.trim().split(RegExp(r'\s+')).where((w) => w.isNotEmpty);
  return words
      .take(2)
      .map((w) => String.fromCharCode(w.runes.first).toUpperCase())
      .join();
}