David PHAM-VAN

Use PageTheme in example

... ... @@ -5,6 +5,7 @@
- Simplify iOS code
- Improve native code
- Add Printing.info()
- Use PageTheme in example
## 2.1.9
... ...
... ... @@ -18,12 +18,10 @@ Future<Document> generateDocument(PdfPageFormat format) async {
print('Unable to download image');
});
pdf.addPage(MyPage(
pageFormat: format.applyMargin(
left: 2.0 * PdfPageFormat.cm,
top: 4.0 * PdfPageFormat.cm,
right: 2.0 * PdfPageFormat.cm,
bottom: 2.0 * PdfPageFormat.cm),
final PageTheme pageTheme = myPageTheme(format);
pdf.addPage(Page(
pageTheme: pageTheme,
build: (Context context) => Row(children: <Widget>[
Expanded(
child: Column(
... ...
... ... @@ -6,48 +6,54 @@ import 'package:qr/qr.dart';
const PdfColor green = PdfColor.fromInt(0xff9ce5d0);
const PdfColor lightGreen = PdfColor.fromInt(0xffcdf1e7);
class MyPage extends Page {
MyPage(
{PdfPageFormat pageFormat = PdfPageFormat.a4,
BuildCallback build,
EdgeInsets margin})
: super(pageFormat: pageFormat, margin: margin, build: build);
@override
void paint(Widget child, Context context) {
PageTheme myPageTheme(PdfPageFormat format) {
return PageTheme(
pageFormat: format.applyMargin(
left: 2.0 * PdfPageFormat.cm,
top: 4.0 * PdfPageFormat.cm,
right: 2.0 * PdfPageFormat.cm,
bottom: 2.0 * PdfPageFormat.cm),
buildBackground: (Context context) {
return FullPage(
ignoreMargins: true,
child: CustomPaint(
size: PdfPoint(format.width, format.height),
painter: (PdfGraphics canvas, PdfPoint size) {
context.canvas
..setColor(lightGreen)
..moveTo(0, pageFormat.height)
..lineTo(0, pageFormat.height - 230)
..lineTo(60, pageFormat.height)
..moveTo(0, size.y)
..lineTo(0, size.y - 230)
..lineTo(60, size.y)
..fillPath()
..setColor(green)
..moveTo(0, pageFormat.height)
..lineTo(0, pageFormat.height - 100)
..lineTo(100, pageFormat.height)
..moveTo(0, size.y)
..lineTo(0, size.y - 100)
..lineTo(100, size.y)
..fillPath()
..setColor(lightGreen)
..moveTo(30, pageFormat.height)
..lineTo(110, pageFormat.height - 50)
..lineTo(150, pageFormat.height)
..moveTo(30, size.y)
..lineTo(110, size.y - 50)
..lineTo(150, size.y)
..fillPath()
..moveTo(pageFormat.width, 0)
..lineTo(pageFormat.width, 230)
..lineTo(pageFormat.width - 60, 0)
..moveTo(size.x, 0)
..lineTo(size.x, 230)
..lineTo(size.x - 60, 0)
..fillPath()
..setColor(green)
..moveTo(pageFormat.width, 0)
..lineTo(pageFormat.width, 100)
..lineTo(pageFormat.width - 100, 0)
..moveTo(size.x, 0)
..lineTo(size.x, 100)
..lineTo(size.x - 100, 0)
..fillPath()
..setColor(lightGreen)
..moveTo(pageFormat.width - 30, 0)
..lineTo(pageFormat.width - 110, 50)
..lineTo(pageFormat.width - 150, 0)
..moveTo(size.x - 30, 0)
..lineTo(size.x - 110, 50)
..lineTo(size.x - 150, 0)
..fillPath();
super.paint(child, context);
}
},
),
);
},
);
}
class Block extends StatelessWidget {
... ...