Flutter将图像从文件系统添加到pdf

时间:2020-05-26 09:00:39

标签: image flutter pdf

下面的代码我必须在flutter中将pdf插入图像,图像以png格式保存在文件系统中,我要做的是恢复图像,然后在运行时将其添加到pdf中代码我有以下错误:

错误:

Unhandled Exception: 'package:pdf/widgets/image.dart': Failed assertion: line 87 pos 16: 'image != null': is not true.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:42:39)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:38:5)
#2      new Image (package:pdf/widgets/image.dart:87:16)
#3      writeOnPdf.<anonymous closure> (package:myapp/View/Rapportini/GenerazioneRapportini/GenerazionePDF/GenerazionePDF.dart:130:19)
#4      MultiPage.generate (package:pdf/widgets/multi_page.dart:171:45)
#5      Document.addPage (package:pdf/widgets/document.dart:65:10)
#6      writeOnPdf (package:myapp/View/Rapportini/GenerazioneRapportini/GenerazionePDF/GenerazionePDF.dart:102:9)
#7      generaRapporto (package:myapp/View/Rapportini/GenerazioneRapportini/GenerazionePDF/GenerazionePDF.dart:182:3)
<asynchronous suspension>
#8      verificaCampi (package:myapp/View/Rapportini/GenerazioneRapportini/GenerazionePDF/GenerazionePDF.dart:50:2)
#9  <…>

代码:

  Uint8List testataCodificata=await Rapporto.getTestata(context);

  profileImage = PdfImage.file(
    pdf.document,
    bytes: testataCodificata,
  );

    new Future.delayed(const Duration(seconds: 2), () => "2");
  String pathFirma=await Storage.leggi("PathFirma");


  final ByteData bytes = await rootBundle.load(pathFirma);

  final Uint8List bytesfirma = bytes.buffer.asUint8List();

  firmaImage = PdfImage.file(
    pdf.document,
    bytes: bytesfirma,
  );

0 个答案:

没有答案
相关问题