我有一個 api 可以從 mysql DB 獲取庫存。構建串列視圖作業正常。但是對于這個應用程式,我需要使用我從資料庫獲得的值創建一個 PDF,老實說我不知道??如何做到這一點......
我正在使用 pdf 包。我可以創建 PDF,但我不知道如何填寫。
這是我的 API 呼叫函式:
Future<List> getInventory(String _refToSearch) async {
String urlQuery = "";
if (isFromScan == false) {
urlQuery = "http://*****/getinventory.php";
final res = await http.get(Uri.parse(urlQuery));
return jsonDecode(res.body);
} else {
urlQuery = "http://*****/getinventorybyref.php";
Response res =
await Dio().get(urlQuery, queryParameters: {"ref": _refToSearch});
return jsonDecode(res.data);
}
}
感謝您的幫助
uj5u.com熱心網友回復:
我已經使用這種方法從 Rest API 保存了 PDF
Future bioringPdf(String calType) async {
//get pdf from link
var dio = Dio();
// String ManualTechnique = 'Incision depth : ${widget.result['ManualTechnique'].toString()}';
// String FemtoTechnique = 'Tunnel depth : ${widget.result['FemtoTechnique'].toString()}';
Response response = await dio.post(
"https://biotechcalculators.com/apicall/bioring.php",
data: {
"generate_pdf": "yes",
"thickest_model_code": "",
"calculation_id": cal.cal_id,
"lns_img": cal.lens_image
},
options: Options(
responseType: ResponseType.bytes,
followRedirects: false,
validateStatus: (status) {
return status < 500;
}),
);
String path = await ExtStorage.getExternalStoragePublicDirectory(ExtStorage.DIRECTORY_DOWNLOADS);
String fullPath = "$path/$calType ${widget.cal_id}.pdf";
//write in download folder
File file = File(fullPath);
var status = await Permission.storage.status;
if (!status.isGranted) {
await Permission.storage.request();
}
var raf = file.openSync(mode: FileMode.write);
raf.writeFromSync(response.data);
await raf.close();
pdfValidatePopop(context, "PDF have been successfully saved in device");
}
根據您的要求更改正文和其他資料
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/311208.html
