In this Multipage class https://pub.dev/documentation/pdf/latest/widgets/MultiPage-class.html it is clearly mention an inner widget tree cannot be bigger than a page: A Widget cannot be drawn partially on one page and the remaining on another page: It's insecable.
I want to generate the views using this pdf plugin.
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import '../utils/page_data.dart';
makeTemplate3(pw.Document doc, pw.PageTheme pageTheme, PageData pageData,
pw.MemoryImage profileImagee) {
List<LineItems> _product = [];
for (var i = 0; i < 100; i++) {
int pos = i + 1;
_product.add(
LineItems(
id: '$pos',
name: 'Product',
price: '100$i',
quantity: '200$i',
total: 'Total Sum: ' + (i * 200).toString(),
desc:
'Test widget $i: An inner widget tree cannot be bigger than a page: A Widget cannot be drawn partially on one page and the remaining on another page: Its insecable. A small set of Widget can automatically span over multiple pages, and can be used as a direct child of the build method: Flex, Partition, Table, Wrap, GridView, and Column.',
),
);
}
doc.addPage(
pw.MultiPage(
pageTheme: pageTheme,
build: (pw.Context context) => <pw.Widget>[
_headerLayout(),
// ignore: sdk_version_ui_as_code
for (int i = 0; i < _product.length; i++)
_productLayout(_product[i]),
]),
);
return doc;
}
_headerLayout() {
return new pw.Container(
padding: pw.EdgeInsets.all(20.0),
height: 80.0,
color: PdfColors.blue,
child: pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.Container(
child: pw.Text(
'Header',
style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 25),
),
),
],
));
}
_productLayout(LineItems item) {
return new pw.Container(
margin: pw.EdgeInsets.all(20.0),
child: pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Column(crossAxisAlignment: pw.CrossAxisAlignment.start, children: [
pw.Container(
padding: pw.EdgeInsets.only(bottom: 20),
child: pw.Text(
item.name.toString() + ' - ID: ' + item.id.toString(),
style:
pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 20),
),
),
pw.Container(
padding: pw.EdgeInsets.only(bottom: 10),
child: pw.Text(
'Qty: ' +
item.quantity.toString() +
' x Cost: £' +
item.price,
style: pw.TextStyle(
fontWeight: pw.FontWeight.normal, fontSize: 16)),
),
pw.Container(
padding: pw.EdgeInsets.only(bottom: 10),
child: pw.Text(
'£' + item.total.toString(),
style: pw.TextStyle(
fontWeight: pw.FontWeight.normal, fontSize: 14),
)),
pw.Text('Description: ' + item.desc,
style: pw.TextStyle(
fontWeight: pw.FontWeight.normal, fontSize: 16)),
getSubItemList()
]),
],
));
}
pw.Widget getSubItemList() {
List<pw.Container> list = [];
for (int i = 0; i < 25; i++) {
list.add(
pw.Container(
child: pw.Text(
'Sub Product: $i Total Sum: $i-475',
style: pw.TextStyle(
fontWeight: pw.FontWeight.normal, fontSize: 16))),
);
}
return pw.Container(
padding: pw.EdgeInsets.all(20), child: pw.Column(children: list));
}
class LineItems {
String total, price, quantity, name, id, desc;
LineItems(
{this.total, this.price, this.quantity, this.name, this.id, this.desc});
}
It's not a complicated layout. All you need to do is flatten every block down to the MultiPage children.
Try this: