createBuilds static method

Future<AppBuildsUpload> createBuilds(
  1. Client cloudApiClient, {
  2. required String projectId,
  3. required List<FlutterPlatform> platforms,
  4. required Map<FlutterPlatform, String> appIdentifiers,
  5. required String flutterAppDir,
  6. required int archiveSize,
  7. String? versionName,
  8. GitMetadata? gitMetadata,
})

Requests a build of the Flutter app in flutterAppDir of the archive for each of platforms in project projectId, and returns the build ids with the upload description for an archive of archiveSize bytes.

appIdentifiers holds the app identifier the app declares for each of platforms. Serverpod Cloud records each one, and the result lists the ones that replaced a different identifier. versionName is the app version the builds are made with.

Throws FailureException if the request fails, if an app identifier is invalid, or if the publishing setup of a platform is incomplete.

Implementation

static Future<AppBuildsUpload> createBuilds(
  Client cloudApiClient, {
  required String projectId,
  required List<FlutterPlatform> platforms,
  required Map<FlutterPlatform, String> appIdentifiers,
  required String flutterAppDir,
  required int archiveSize,
  String? versionName,
  GitMetadata? gitMetadata,
}) async {
  final appPlatforms = platforms.map(_appPlatform).toList();

  try {
    return await cloudApiClient.appBuilds.createBuilds(
      cloudCapsuleId: projectId,
      platforms: appPlatforms,
      appIdentifiers: {
        for (final MapEntry(key: platform, value: appIdentifier)
            in appIdentifiers.entries)
          _appPlatform(platform): appIdentifier,
      },
      flutterAppDir: flutterAppDir,
      archiveSize: archiveSize,
      versionName: versionName,
      commitHash: gitMetadata?.commitHash,
      commitMessage: gitMetadata?.commitMessage,
      branch: gitMetadata?.branch,
    );
  } on UploadTooLargeException catch (e) {
    throw FailureException(
      error: e.message,
      hint: 'Exclude files from the app with a .scloudignore file.',
    );
  } on AppPublishingDisabledException catch (e) {
    throw FailureException(error: e.message);
  } on AppPlatformNotSetUpException catch (e) {
    throw FailureException(error: e.message);
  } on InvalidValueException catch (e) {
    throw FailureException(error: e.message);
  } on NotFoundException catch (e) {
    throw FailureException(error: e.message);
  } on Exception catch (e, stackTrace) {
    throw FailureException.nested(
      e,
      stackTrace,
      'Failed to request the app builds.',
    );
  }
}