secondWord method

  1. @useResult
String? secondWord()

Returns the second word of this string, or null if fewer than two words.

Implementation

@useResult
String? secondWord() {
  if (isEmpty) {
    return null;
  }

  final List<String>? wordList = words();
  if (wordList == null || wordList.length < 2) {
    return null;
  }

  return wordList[1];
}