generate method

Future<PasskitGenerated> generate({
  1. required String id,
  2. required Directory directory,
  3. required PasskitPass passkitPass,
  4. required File pkpass,
  5. required File signature,
  6. required File manifest,
  7. PasskitImage? backgroundImage,
  8. PasskitImage? footerImage,
  9. PasskitImage? iconImage,
  10. PasskitImage? logoImage,
  11. PasskitImage? stripImage,
  12. PasskitImage? thumbnailImage,
  13. bool override = false,
})

Implementation

Future<PasskitGenerated> generate({
  required final String id,
  required final Directory directory,
  required final PasskitPass passkitPass,
  required final File pkpass,
  required final File signature,
  required final File manifest,
  PasskitImage? backgroundImage,
  PasskitImage? footerImage,
  PasskitImage? iconImage,
  PasskitImage? logoImage,
  PasskitImage? stripImage,
  PasskitImage? thumbnailImage,
  bool override = false,
}) async {
  final fs = Fs();
  final directory = await fs.createDirectory(name: 'passes');
  final childDirectory = Directory('${directory.path}/$id');
  final creators = Creators(directory: childDirectory);

  await Future.wait([
    if (iconImage != null) creators.copyImage(iconImage, name: 'icon'),
    if (logoImage != null) creators.copyImage(logoImage, name: 'logo'),
    if (footerImage != null) creators.copyImage(footerImage, name: 'footer'),
    if (stripImage != null) creators.copyImage(stripImage, name: 'stripe'),
    if (thumbnailImage != null)
      creators.copyImage(thumbnailImage, name: 'thumbnail'),
    if (backgroundImage != null)
      creators.copyImage(backgroundImage, name: 'background'),
  ]);

  final creatorFutures = await Future.wait([
    creators.preparePkpass(id),
    creators.createPass(passkitPass),
  ]);

  final manifestPath = '${childDirectory.path}/manifest.json';
  final manifestBytes = manifest.readAsBytesSync();
  final manifestFile = File(manifestPath)
    ..createSync(recursive: true)
    ..writeAsBytesSync(manifestBytes);

  final signaturePath = '${childDirectory.path}/signature';
  final signatureBytes = signature.readAsBytesSync();
  final signatureFile = File(signaturePath)
    ..createSync(recursive: true)
    ..writeAsBytesSync(signatureBytes);

  final passkitFile = PasskitFile(
    id: id,
    file: pkpass,
    directory: directory,
    json: passkitPass,
    background: backgroundImage,
    footer: footerImage,
    icon: iconImage,
    logo: logoImage,
    strip: stripImage,
    thumbnail: thumbnailImage,
  );

  fs.pack(directory: childDirectory, filename: creatorFutures[0].path);

  return PasskitGenerated(
    directory: childDirectory,
    passkitFile: passkitFile,
    manifestFile: manifestFile,
    signatureFile: signatureFile,
    passFile: creatorFutures[1],
  );
}