TypeError: Cannot read properties of undefined (reading 'bigEndian')

Custom Code

I want to generate and download a PDF but get a TypeError: Cannot read properties of undefined (reading 'bigEndian').

What have you tried so far?

I’ve tried printing, saving normally, and even creating a very simple PDF, but I keep getting errors or the PDF doesn’t generate at all.

Code:

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

Future<void> downloadBasicPdf(BuildContext context) async {
  try {
    final pdf = pw.Document();
    print('PDF-Objekt erstellt');

    final rows = <pw.TableRow>[];

    // Tabellenkopf
    rows.add(
      pw.TableRow(
        children: [
          _headerCell('Datum'),
          _headerCell('Ort'),
          _headerCell('Beginn'),
          _headerCell('Ende'),
          _headerCell('Pause'),
          _headerCell('Aufgabe'),
        ],
      ),
    );

    // Dummy-Datenzeilen
    rows.addAll(List.generate(2, (index) {
      return pw.TableRow(
        children: [
          _cell('01.05.2025'),
          _cell('Berlin'),
          _cell('08:00'),
          _cell('16:00'),
          _cell('0.5'),
          _cell('Beratung'),
        ],
      );
    }));

    pdf.addPage(
      pw.MultiPage(
        pageFormat: PdfPageFormat.a4,
        margin: pw.EdgeInsets.all(25),
        build: (context) => [
          pw.Text('Test PDF'),
          pw.SizedBox(height: 20),
          pw.Table(
            border: pw.TableBorder.all(),
            children: rows,
          ),
        ],
      ),
    );
    print('Seite hinzugefügt');

    final Uint8List bytes = await pdf.save();
    print('PDF-Daten gespeichert');

    final blob = html.Blob([bytes], 'application/pdf');
    final url = html.Url.createObjectUrlFromBlob(blob);
    final anchor = html.AnchorElement(href: url)
      ..setAttribute('download', 'test_table.pdf')
      ..click();
    html.Url.revokeObjectUrl(url);
    print('Download gestartet');

    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text('PDF wurde erfolgreich heruntergeladen.')),
    );
  } catch (e, stack) {
    print('Fehler beim PDF-Export: $e');
    print(stack);
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text('Fehler beim PDF-Export: $e')),
    );
  }
}

pw.Widget _headerCell(String text) => pw.Center(
      child: pw.Text(text,
          style: pw.TextStyle(fontSize: 10, fontWeight: pw.FontWeight.bold),
          textAlign: pw.TextAlign.center),
    );

pw.Widget _cell(String text) => pw.Center(
      child: pw.Text(text, style: pw.TextStyle(fontSize: 10)),
    );
Did you check FlutterFlow's Documentation for this topic?
No
4
4 replies