I'm currently facing a bug while working with the pdf package in Flutter. I'm using the MultiPage widget to create a PDF document and dynamically add new pages when the content overflows. The package is designed to create new pages automatically, but I'm encountering an error that I can't seem to resolve.
To explain the issue further, when I add the same widget, it correctly creates page 1. When I add more of the same widget, it creates page 2 as expected. However, when I continue adding widgets, instead of creating page 3, I receive an exception.
_Exception (Exception: This widget created more than 50 pages. This may be an issue in the widget or the document. See https://pub.dev/documentation/pdf/latest/widgets/MultiPage-class.html)
I've followed the documentation and guidelines for the MultiPage class, but I can't seem to resolve this issue. Has anyone encountered a similar problem or found a workaround for it? Any insights or suggestions would be greatly appreciated.
Thank you for your assistance
Future<void> generate() async {
final logo = await _logo();
final pdf = pw.Document();
pdf.addPage(pw.MultiPage(
pageFormat: PdfPageFormat.a4,
maxPages: 50,
build: (pw.Context context) {
return [
pw.Column(
children: [
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.center,
children: [
logo,
pw.Text(
Texts.title.toUpperCase(),
textAlign: pw.TextAlign.center,
style: pw.TextStyle(
fontSize: 18,
fontWeight: pw.FontWeight.bold,
),
),
],
),
_buildTableDadosTransformador(),
_buildTablePotencia(),
_buildTableNucleo(),
_buildTablePrimario(),
_buildTableSecundarios(),
],
)
];
},
));
savePDF(pdf);
}