stableReleasesOf function

Map<Version, FlutterRelease> stableReleasesOf(
  1. Object? json,
  2. FlutterSystem system
)

The stable releases of Flutter for system in json, its list of releases (FlutterSystem.releases), by version: those for the architecture of system whose version is plain, such as 3.44.2, and not v1.12.13+hotfix.9. The Dart of a release is the version that starts its dart_sdk_version, such as 3.10.0 of 3.10.0 (build 3.10.0-290.4.beta).

The list has the newest release first. A version that was released twice keeps its first entry, of the newest archive, which replaced the other.

Throws a FormatException if json is not a list of releases.

Implementation

Map<Version, FlutterRelease> stableReleasesOf(
  Object? json,
  FlutterSystem system,
) {
  if (json case {'releases': final List<Object?> releases}) {
    final byVersion = <Version, FlutterRelease>{};
    for (final release in releases) {
      if (release
          case {
            'channel': 'stable',
            'version': final String flutterText,
            'dart_sdk_version': final String dartText,
            'dart_sdk_arch': final String arch,
            'sha256': final String sha256,
          } when arch == system.arch) {
        if ((_version(flutterText), _version(dartText.split(' ').first))
            case (final Version version, final Version dart)
            when version.preRelease.isEmpty && version.build.isEmpty) {
          byVersion.putIfAbsent(
            version,
            () => FlutterRelease(version, dart: dart, sha256: sha256),
          );
        }
      }
    }
    return byVersion;
  }
  throw FormatException(
    'The list of releases of Flutter for ${system.name} has no releases.',
  );
}