I am working in a project where I have to show certificate that the user finished a course, there is an URL of the API that uses the get method within a token to have acces to a pdf file, the problem is that I do not know how to show or transform that response into a pdf, using flutter, I tried to use the url_launcher dependency because in the browser shows the pdf normally, but the problem is that it I need to pass a token to that url. the second thing that i tried was to fetched the response of the api and save it in a temporal file and use flutter_pdfview dependency but it shows errors. this is how the response of the api looks like:
%PDF-1.4
1 0 obj
<<
/Title (þÿ)
/Creator (þÿ)
/Producer (þÿQt 5.5.1)
/CreationDate (D:20211120205047)
>>
endobj
2 0 obj
<<
/Type /Catalog
/Pages 3 0 R
>>
endobj
4 0 obj
<<
/Type /ExtGState
/SA true
/SM 0.02
/ca 1.0
/CA 1.0
/AIS false
this is what I tried:
Future LoadPDF(APIurl)async {
Map<String,String> Headers={
'Content-type': 'application/json; charset=UTF-8',
'Accept': 'application/json',
'Authorization': 'Bearer $userToken'
};
final response = await http.get(Uri.parse(APIurl),headers: Headers);
final bytes = response.bodyBytes;
// print(response.bodyBytes);
var dir = await getTemporaryDirectory();
File file = File(dir.path + "/data.pdf");
await file.writeAsBytes(bytes, flush: true);
setState(() {
loadDocument(file);
});
// return file;
}