loadPkpassFileFromNetworkAsBase64 static method
Downloads a PKPass file from the specified url
and returns its contents
encoded as a base64 string.
The url
parameter should point to a valid PKPass file on the internet.
Optional headers
can be provided for the HTTP GET request.
Returns a Future that completes with the base64-encoded string if the download is successful.
Throws an Exception if the file could not be downloaded or the response has a status code other than 200.
Implementation
static Future<String> loadPkpassFileFromNetworkAsBase64({
required String url,
Map<String, String>? headers,
}) async {
final response = await http.get(Uri.parse(url), headers: headers);
if (response.statusCode == 200) {
final bytes = response.bodyBytes;
return base64Encode(bytes);
} else {
throw Exception('Failed to download pkpass file: ${response.statusCode}');
}
}