fetchReleases method

  1. @override
Future<Map<BuildChannel, Release>> fetchReleases()
override

Fetches all releases for all build channels. Returns a map of BuildChannel to Release.

Implementation

@override
Future<Map<BuildChannel, Release>> fetchReleases() async {
  var response = await networkService
      .get("$kLBPlannerWebsiteAdress/api/get_app_versions.php");

  if (response.isNotOk) {
    throw Exception("Failed to fetch releases: ${response.statusCode}");
  }

  var json = response.body as JSON;

  var releases = <BuildChannel, Release>{};

  for (var entry in json.entries) {
    var channel = BuildChannel.values.byName(entry.key);

    var body = entry.value as JSON;

    /// Add the channel name to the release JSON for parsing.
    body["channel"] = channel.name;

    var release = Release.fromJson(body);
    releases[channel] = release;
  }

  return releases;
}