Flutter -PDF -- 错误 - 这个小部件创建了 20 多个页面.这可能是小部件或文档中的问题 [英] Flutter -PDF -- Error - This widget created more than 20 pages. This may be an issue in the widget or the document
问题描述
我正在创建一个包含大量内容的 PDF 文档.但是,我无法显示 PDF,并且出现错误
I am creating a PDF document that has a large content. However, I am not able to show the PDF and I get the error
这个小部件创建了 20 多个页面.这可能是小部件或文档中的问题."
"This widget created more than 20 pages. This may be an issue in the widget or the document."
我知道文本太大,但我不知道如何使它工作
I know the text is too large but I don't know how to make it work
pdf.addPage(
pw.MultiPage(
pageFormat: PdfPageFormat.a4,
orientation: pw.PageOrientation.portrait,
crossAxisAlignment: pw.CrossAxisAlignment.start,
build: (pw.Context context) {
return <pw.Widget>[
pw.Wrap(
children: <pw.Widget>[
pw.Container(
width: PdfPageFormat.a4.width,
child: pw.Row(
mainAxisSize: pw.MainAxisSize.min,
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Expanded(
child: pw.Column(
mainAxisSize: pw.MainAxisSize.min,
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.SizedBox(height: 8.0),
for (int i = 0; i < data['employers'].length; i++)
pw.Column(
mainAxisSize: pw.MainAxisSize.min,
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Text(
"${data['employers'][i]['duties']}",
style: pw.TextStyle(
fontSize: 12.0,
),
softWrap: true,
),
],
),
],
),
),
],
),
),
],
),
];
},
),
);
我需要一些关于如何重组代码的帮助,以便我可以显示 PDF 并将其换行到下一页文本只是一组 Lorem Ipsum .
I need some help on how to restructure my code so that I can display the PDF and have it wrap to the next page The text is just a a set of Lorem Ipsum .
感谢您的帮助
推荐答案
这个 可能是您问题的解决方案
This might be a solution for your question
我粘贴链接的代码以防您无法输入.
I paste the link's code in case you can't enter it.
假设我们有一个列表issues
:
pdf.addPage(
MultiPage(
build: (Context context) => <Widget>[
Wrap(
children: List<Widget>.generate(issues.length, (int index) {
final issue = issues[index];
return Container(
child: Column(
children: <Widget>[
Header(
text: "Issue n°${issue.id}",
textStyle: TextStyle(fontSize: 20)),
Text("Description :",
textAlign: TextAlign.left,
style: TextStyle(fontSize: 15)),
],
),
);
}),
),
],
),
);
这篇关于Flutter -PDF -- 错误 - 这个小部件创建了 20 多个页面.这可能是小部件或文档中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!