title: Flutter pdf multiple images
body: <p>I'm trying to load multiple images (from assets or cache) into the pdf, but it does not work.
  There are no errors, the pdf is created, but is corrupted somehow and does not want to open.
  Everything is 100% if there is only 1 image, or if all the images are the same image.
  What am I doing wrong?</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:flutter/services.dart';
  import 'dart:io';
  import 'package:path_provider/path_provider.dart';
  import 'package:pdf/pdf.dart';
  import 'package:pdf/widgets.dart' as pw;
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
          home: Scaffold(
              appBar: AppBar(backgroundColor: Colors.red, title: Text('Images')),
              body: Center(child: HomeScreen())));
    }
  }
  
  class HomeScreen extends StatefulWidget {
    HomeScreenState createState() =&gt; HomeScreenState();
  }
  
  class HomeScreenState extends State&lt;HomeScreen&gt; {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          body: Center(
        child: ListView(
          children: &lt;Widget&gt;[
            RaisedButton(
              color: Colors.red,
              onPressed: () async {
                writeOnPdf();
                await savePdf();
              },
              child: Text('Create Pdf'),
            ),
          ],
        ),
      ));
    }
  }
  
  final pdf = pw.Document();
  
  writeOnPdf() async {
    var assetImage = PdfImage.file(
      pdf.document,
      bytes: (await rootBundle.load('assets/aa.png')).buffer.asUint8List(),
    );
  
    var otherImage = PdfImage.file(
      pdf.document,
      bytes: (await rootBundle.load('assets/out.png')).buffer.asUint8List(),
    );
  
    pdf.addPage(pw.MultiPage(
        pageFormat: PdfPageFormat.a4,
        margin: pw.EdgeInsets.all(32),
        build: (pw.Context context) {
          return &lt;pw.Widget&gt;[
            pw.Column(
                crossAxisAlignment: pw.CrossAxisAlignment.center,
                mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
                children: &lt;pw.Widget&gt;[
                  pw.ClipRect(
                    child: pw.Container(
                      width: 550,
                      height: 250,
                      child: pw.Image(assetImage),
                    ),
                  ),
                ]),
            pw.ClipRect(
              child: pw.Container(
                width: 100,
                height: 100,
                child: pw.Image(otherImage),
              ),
            )
          ];
        }));
  }
  
  final bool isHTML = false;
  
  Future savePdf() async {
    Directory tempDir = await getTemporaryDirectory();
    String tempPath = tempDir.path;
    File file = File('$tempPath/1234.pdf');
    file.writeAsBytesSync(pdf.save());
    print(tempDir.listSync());
  }
  </code></pre>
  <p>It would be ideal if I could load one image from the assets and one image from the cache. But at the moment nothing works.
  Any advice would be appreciated.</p>