hasSameCharacters method Null safety

bool? hasSameCharacters()

Checks if the string is consisted of same characters (ignores cases).

Example

String foo1 = 'ttttttt'
bool hasSame1 = foo.hasSameCharacters() // true;
String foo = 'ttttttt12'
bool hasSame2 = foo.hasSameCharacters() // false;

Implementation

bool? hasSameCharacters() {
  if (this == null) {
    return null;
  }
  if (this!.isEmpty) {
    return false;
  }
  if (this!.length > 1) {
    var b = this![0].toLowerCase();
    for (var i = 1; i < this!.length; i++) {
      var c = this![i].toLowerCase();
      if (c != b) {
        return false;
      }
    }
  }
  return true;
}