如何将整个 flutter Screen 转换为 pdf?

Bas*_*yak 10 flutter

我有一个 flutter 电子商务应用程序,其中有一个 orderDetails 页面,我想使用 flutter pdf 包将整个页面转换为 pdf,因为数据是从 FirebaseFirestore 检索的,这样会更方便。有什么办法可以实现这一目标吗?

sub:我想使用这个库将整个颤动屏幕转换为pdf

Ish*_*sha 8

您可以使用此包屏幕截图来捕获屏幕

然后将该图像添加到 pdf 文档并保存

import 'dart:io';
import 'dart:typed_data';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart ' as pw;

Future getPdf(Uint8List screenShot) async {
  pw.Document pdf = pw.Document();
  pdf.addPage(
    pw.Page(
      pageFormat: PdfPageFormat.a4,
      build: (context) {
        return pw.Expanded(
          child: pw.Image(PdfImage.file(pdf.document, bytes: screenShot), fit: pw.BoxFit.contain)
        );
      },
    ),
  );
  File pdfFile = File('Your path + File name');
  pdfFile.writeAsBytesSync(pdf.save());
}
Run Code Online (Sandbox Code Playgroud)