I am creating a PDF document with dynamic data. However, I am not able to show the PDF and I get the error
"This widget created more than 20 pages. This may be an issue in the widget or the document."
i used listview builder but not working check below code and help me
import 'package:pdf/pdf.dart'; import 'package:pdf/widgets.dart' as pw;
pdf.addPage(
pw.MultiPage(
header: (pw.Context context) {
if (context.pageNumber == 1) {
return null;
}
return pw.Container(
alignment: pw.Alignment.centerRight,
margin:
const pw.EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
padding:
const pw.EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
child: pw.Text(reportListDetail[i].location,
style: pw.Theme.of(context)
.defaultTextStyle
.copyWith(color: PdfColors.grey)));
},
footer: (pw.Context context) {
return pw.Container(
alignment: pw.Alignment.centerRight,
margin: const pw.EdgeInsets.only(top: 1.0 * PdfPageFormat.cm),
child: pw.Text(
'Page ${context.pageNumber} of ${context.pagesCount}',
style: pw.Theme.of(context)
.defaultTextStyle
.copyWith(color: PdfColors.grey)));
},
build: (pw.Context context) => <pw.Widget>[
pw.Wrap
(
children: <pw.Widget>[
pw.ListView(
children: [
/* pw.Container(
margin: pw.EdgeInsets.only(top: 20, bottom: 30),
alignment: pw.Alignment.center,
child: pw.Text(reportListDetail[i].location),
),*/
pw.ListView.builder(
itemCount: reportListDetail.length,
itemBuilder: (pw.Context ctxt, int main) {
return pw.ListView(
children:
[
pw.Container(
margin: pw.EdgeInsets.only(top: 20, bottom: 10),
alignment: pw.Alignment.topLeft,
child:
pw.Text(reportListDetail[main].subjectName),
),
pw.GridView(
crossAxisCount: 2,
childAspectRatio: 1,
children: List.generate(
reportListDetail[main].subjctList.length,
(index) {
bool isMatched = false;
var image;
var d = reportListDetail[main]
.subjctList[index]
.imageName
.split(".");
String type = "";
for (int i = 0; i < d.length; i++) {
if (i == (d.length - 1)) {
type = d[i];
}
}
String typeLowerCase = type.toLowerCase();
if (videoExtensionList
.contains(typeLowerCase)) {
setState(() {
isMatched = true;
});
} else {
setState(() {
isMatched = false;
});
}
return pw.Container(
child: pw.ListView(children: [
pw.Container(
alignment: pw.Alignment.topLeft,
margin: pw.EdgeInsets.only(left: 10),
child: pw.Text(reportListDetail[main]
.subjctList[index]
.captionName)),
isMatched
? pw.Flexible(
child: pw.SizedBox(
width: 350,
height: 200,
child: pw.FittedBox(
fit: pw.BoxFit.fitWidth,
alignment:
pw.Alignment.topLeft,
child: pw.Text(
"https://drive.google.com/uc?export=download&id=" +
reportListDetail[main]
.subjctList[index]
.id,
maxLines: 3,
))))
: pw.Image.provider(
pw.MemoryImage(File(
reportListDetail[main]
.subjctList[index]
.imageName)
.readAsBytesSync()),
width: 200,
height: 200,
fit: pw.BoxFit.cover),
]));
}),
),
]);
}),
],
)
]
)
]
)
);