saveFromUri method

Future<PasskitFile> saveFromUri({
  1. required String id,
  2. required String url,
})

Implementation

Future<PasskitFile> saveFromUri({
  required String id,
  required String url,
}) async {
  Directory directory = await fs.createDirectory(name: directoryName);
  final file = File('${directory.path}/$id.pkpass')..createSync();

  directory = Directory(Path.withoutExtension(file.path));
  final response = await Dio().download(url, file.path);

  if (response.statusCode != 200) {
    throw new Exception('Unable to download passkit');
  }

  await fs.unpack(path: file.path);

  final passkitFile = File('${directory.path}/pass.json');
  if (!passkitFile.existsSync()) throw Exception('Missing pass.json');

  return Parser(
    id: id,
    directory: directory,
    file: file,
    passFile: passkitFile,
  ).parse();
}