gpt4 book ai didi

Flutter -PDF -- 错误 - 这个小部件创建了 20 多个页面。这可能是小部件或文档中的问题

转载 作者:行者123 更新时间:2023-12-03 14:53:41 24 4
gpt4 key购买 nike

我正在创建一个包含大量内容的 PDF 文档。但是,我无法显示 PDF 并且出现错误

“这个小部件创建了 20 多个页面。这可能是小部件或文档中的问题。”

我知道文字太大,但我不知道如何使它起作用

    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 。

谢谢你的帮助

最佳答案

你可以简单地使用它。

import 'package:ferns_restaurant/constants/Constants.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:pdf/widgets.dart';
import 'package:printing/printing.dart';
import 'package:woocommerce/models/order.dart';

class CustomPrinter {
final pdf = pw.Document();

print(WooOrder order) {
List<LineItems> _product = order.lineItems;

Printing.layoutPdf(
onLayout: (format) {
final doc = pw.Document();
doc.addPage(
pw.MultiPage(
crossAxisAlignment: pw.CrossAxisAlignment.start,
build: (pw.Context context) => <pw.Widget>[
_topHeaderLayout(),
for (int i = 0; i < _product.length; i++)
_productLayout(_product[i]),
]),
);
return doc.save();
},
name: 'order_id_#' + order.id.toString(),
);
}

_topHeaderLayout() {
return new pw.Container(
// height: 60.0,
margin: pw.EdgeInsets.only(bottom: 20.0),
child: pw.Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
pw.Expanded(
child: pw.Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Container(
child: pw.Text(
'ITEM',
style: pw.TextStyle(
fontWeight: pw.FontWeight.bold,
fontSize: Constants.PRINTER_BASE_FONT_SIZE),
),
),
],
),
),
pw.Expanded(
child: pw.Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <pw.Widget>[
pw.Text(
'PRICE',
style: pw.TextStyle(
fontWeight: pw.FontWeight.bold,
fontSize: Constants.PRINTER_BASE_FONT_SIZE),
),
],
),
)
],
));
}

_productLayout(LineItems item) {
return new pw.Container(
// height: 60.0,
margin: pw.EdgeInsets.only(bottom: 20.0),
child: pw.Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
pw.Expanded(
child: pw.Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Container(
child: pw.Text(
item.name.toString() + ' - ID: ' + item.id.toString(),
style: pw.TextStyle(
fontWeight: pw.FontWeight.bold,
fontSize: Constants.PRINTER_BASE_FONT_SIZE),
),
),
pw.Container(
child: Text(
'Qty: ' +
item.quantity.toString() +
' x Cost: ' +
'£' +
item.price,
style: pw.TextStyle(
fontWeight: pw.FontWeight.normal,
fontSize: Constants.PRINTER_BASE_FONT_SIZE)),
),
],
),
),
pw.Expanded(
child: pw.Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <pw.Widget>[
pw.Text(
'£' + item.total.toString(),
style: pw.TextStyle(
fontWeight: pw.FontWeight.normal,
fontSize: Constants.PRINTER_BASE_FONT_SIZE),
),
],
),
)
],
));
}
}

关于Flutter -PDF -- 错误 - 这个小部件创建了 20 多个页面。这可能是小部件或文档中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61679628/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com