isOneAKind method Null safety

bool isOneAKind(
  1. dynamic value
)

Checks if all data have same value. Example: 111111 -> true, wwwww -> true, 1,1,1,1 -> true

Implementation

static bool isOneAKind(dynamic value) {
  if ((value is String || value is List) && !isNullOrBlank(value)!) {
    final first = value[0];
    final len = value.length as num;

    for (var i = 0; i < len; i++) {
      if (value[i] != first) {
        return false;
      }
    }

    return true;
  }

  if (value is int) {
    final stringValue = value.toString();
    final first = stringValue[0];

    for (var i = 0; i < stringValue.length; i++) {
      if (stringValue[i] != first) {
        return false;
      }
    }

    return true;
  }

  return false;
}