validateBlurhash function

bool validateBlurhash(
  1. String blurhash
)

Implementation

bool validateBlurhash(String blurhash) {
  if (blurhash.isEmpty || blurhash.length < 6) {
    debugPrint('Blurhash should be at least 6 characters');
    return false;
  }

  final sizeFlag = _decode83(blurhash[0]);
  final y = ((sizeFlag / 9) + 1).floor();
  final x = (sizeFlag % 9) + 1;

  if (blurhash.length != 4 + 2 * x * y) {
    debugPrint(
        "blurhash length mismatch: length is ${blurhash.length} but it should be ${4 + 2 * x * y}");
    return false;
  }

  return true;
}