fromUrl static method

Future<PKPass> fromUrl(
  1. Uri url, {
  2. Map<String, String?>? headers,
})

Creates a new PKPass object from a given Uri. Additional headers can be sent with the headers parameter.

Will throw a DioException on network error

Example:

final Uri uri = Uri.parse("https://example.com/pass.pkpass");
try {
  final PKPass pass = await PKPass.fromUrl(
    uri,
    headers: {"Authorization": "Bearer ..."},
  );
  pass.save();
} on DioException catch (e) {
  print("Something went wrong...");
  print(e);
}

Implementation

static Future<PKPass> fromUrl(Uri url,
    {Map<String, String?>? headers}) async {
  final dio = Dio();
  final response = await dio.getUri(
    url,
    options: Options(
      headers: headers,
      responseType: ResponseType.bytes,
    ),
  );
  return PKPass._(
    data: response.data,
  );
}