tryParse static method

ProfileLock? tryParse(
  1. Object? value
)

Null for anything but the current shape, including an older lock, which get then rewrites.

Implementation

static ProfileLock? tryParse(Object? value) {
  if (value case <String, Object?>{
    'lock_version': 1,
    'configuration_sha256': final String sha,
    'packages': final Map<String, Object?> rawPackages,
  } when value.length == 3 && RegExp(r'^[0-9a-f]{64}$').hasMatch(sha)) {
    final packages = <ProfileId, LockedPackage>{};
    for (final entry in rawPackages.entries) {
      final id = _profileIdOrNull(entry.key);
      final package = id == null
          ? null
          : LockedPackage._tryParse(id, entry.value);
      if (package == null) return null;
      packages[package.id] = package;
    }
    if (packages.isEmpty) return null;
    return ProfileLock(
      configurationSha256: sha,
      packages: Map.unmodifiable(packages),
    );
  }
  return null;
}