isValidUUID method Null safety

bool isValidUUID (
  1. String uuid
)

Implementation

static bool isValidUUID(String uuid) {
  // UUID of all 0s is ok.
  if (uuid == NAMESPACE_NIL) {
    return true;
  }

  // If its not 36 characters in length, don't bother (including dashes).
  if (uuid.length != 36) {
    return false;
  }

  // Make sure if it passes the above, that its valid.
  const pattern =
      r'^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$';
  final regex = RegExp(pattern, caseSensitive: false, multiLine: true);
  final match = regex.hasMatch(uuid);
  return match;
}