我正在使用flutter制作程序包,我试图在脚手架上预览或显示它,但到目前为止还无法做到。
包链接:https://pub.dev/packages/pdf
这是我的密码
class _PreviewInvoiceState extends State<PreviewInvoice> {
// pdf producer
void makePdf(){
final document = pw.Document();
document.addPage(
pw.Page(
pageFormat: PdfPageFormat.a4,
build: (pw.Context context) {
return pw.Center(child: pw.Text('hello world'));
}
)
);
}
@override
Widget build(BuildContext context) {
return Scaffold(); // trying to display it in the scaffold body property
}
}
发布于 2022-11-24 18:39:16
pdf格式包用于创建pdf。要查看它,必须将其保存到
// On Flutter, use the [path_provider](https://pub.dev/packages/path_provider) library:
// final output = await getTemporaryDirectory();
// final file = File("${output.path}/example.pdf");
final file = File("example.pdf");
await file.writeAsBytes(await pdf.save());
要查看,您必须使用像颤动这样的包。
https://stackoverflow.com/questions/74564935
复制相似问题