Showing
3 changed files
with
41 additions
and
36 deletions
@@ -18,12 +18,10 @@ Future<Document> generateDocument(PdfPageFormat format) async { | @@ -18,12 +18,10 @@ Future<Document> generateDocument(PdfPageFormat format) async { | ||
18 | print('Unable to download image'); | 18 | print('Unable to download image'); |
19 | }); | 19 | }); |
20 | 20 | ||
21 | - pdf.addPage(MyPage( | ||
22 | - pageFormat: format.applyMargin( | ||
23 | - left: 2.0 * PdfPageFormat.cm, | ||
24 | - top: 4.0 * PdfPageFormat.cm, | ||
25 | - right: 2.0 * PdfPageFormat.cm, | ||
26 | - bottom: 2.0 * PdfPageFormat.cm), | 21 | + final PageTheme pageTheme = myPageTheme(format); |
22 | + | ||
23 | + pdf.addPage(Page( | ||
24 | + pageTheme: pageTheme, | ||
27 | build: (Context context) => Row(children: <Widget>[ | 25 | build: (Context context) => Row(children: <Widget>[ |
28 | Expanded( | 26 | Expanded( |
29 | child: Column( | 27 | child: Column( |
@@ -6,48 +6,54 @@ import 'package:qr/qr.dart'; | @@ -6,48 +6,54 @@ import 'package:qr/qr.dart'; | ||
6 | const PdfColor green = PdfColor.fromInt(0xff9ce5d0); | 6 | const PdfColor green = PdfColor.fromInt(0xff9ce5d0); |
7 | const PdfColor lightGreen = PdfColor.fromInt(0xffcdf1e7); | 7 | const PdfColor lightGreen = PdfColor.fromInt(0xffcdf1e7); |
8 | 8 | ||
9 | -class MyPage extends Page { | ||
10 | - MyPage( | ||
11 | - {PdfPageFormat pageFormat = PdfPageFormat.a4, | ||
12 | - BuildCallback build, | ||
13 | - EdgeInsets margin}) | ||
14 | - : super(pageFormat: pageFormat, margin: margin, build: build); | ||
15 | - | ||
16 | - @override | ||
17 | - void paint(Widget child, Context context) { | 9 | +PageTheme myPageTheme(PdfPageFormat format) { |
10 | + return PageTheme( | ||
11 | + pageFormat: format.applyMargin( | ||
12 | + left: 2.0 * PdfPageFormat.cm, | ||
13 | + top: 4.0 * PdfPageFormat.cm, | ||
14 | + right: 2.0 * PdfPageFormat.cm, | ||
15 | + bottom: 2.0 * PdfPageFormat.cm), | ||
16 | + buildBackground: (Context context) { | ||
17 | + return FullPage( | ||
18 | + ignoreMargins: true, | ||
19 | + child: CustomPaint( | ||
20 | + size: PdfPoint(format.width, format.height), | ||
21 | + painter: (PdfGraphics canvas, PdfPoint size) { | ||
18 | context.canvas | 22 | context.canvas |
19 | ..setColor(lightGreen) | 23 | ..setColor(lightGreen) |
20 | - ..moveTo(0, pageFormat.height) | ||
21 | - ..lineTo(0, pageFormat.height - 230) | ||
22 | - ..lineTo(60, pageFormat.height) | 24 | + ..moveTo(0, size.y) |
25 | + ..lineTo(0, size.y - 230) | ||
26 | + ..lineTo(60, size.y) | ||
23 | ..fillPath() | 27 | ..fillPath() |
24 | ..setColor(green) | 28 | ..setColor(green) |
25 | - ..moveTo(0, pageFormat.height) | ||
26 | - ..lineTo(0, pageFormat.height - 100) | ||
27 | - ..lineTo(100, pageFormat.height) | 29 | + ..moveTo(0, size.y) |
30 | + ..lineTo(0, size.y - 100) | ||
31 | + ..lineTo(100, size.y) | ||
28 | ..fillPath() | 32 | ..fillPath() |
29 | ..setColor(lightGreen) | 33 | ..setColor(lightGreen) |
30 | - ..moveTo(30, pageFormat.height) | ||
31 | - ..lineTo(110, pageFormat.height - 50) | ||
32 | - ..lineTo(150, pageFormat.height) | 34 | + ..moveTo(30, size.y) |
35 | + ..lineTo(110, size.y - 50) | ||
36 | + ..lineTo(150, size.y) | ||
33 | ..fillPath() | 37 | ..fillPath() |
34 | - ..moveTo(pageFormat.width, 0) | ||
35 | - ..lineTo(pageFormat.width, 230) | ||
36 | - ..lineTo(pageFormat.width - 60, 0) | 38 | + ..moveTo(size.x, 0) |
39 | + ..lineTo(size.x, 230) | ||
40 | + ..lineTo(size.x - 60, 0) | ||
37 | ..fillPath() | 41 | ..fillPath() |
38 | ..setColor(green) | 42 | ..setColor(green) |
39 | - ..moveTo(pageFormat.width, 0) | ||
40 | - ..lineTo(pageFormat.width, 100) | ||
41 | - ..lineTo(pageFormat.width - 100, 0) | 43 | + ..moveTo(size.x, 0) |
44 | + ..lineTo(size.x, 100) | ||
45 | + ..lineTo(size.x - 100, 0) | ||
42 | ..fillPath() | 46 | ..fillPath() |
43 | ..setColor(lightGreen) | 47 | ..setColor(lightGreen) |
44 | - ..moveTo(pageFormat.width - 30, 0) | ||
45 | - ..lineTo(pageFormat.width - 110, 50) | ||
46 | - ..lineTo(pageFormat.width - 150, 0) | 48 | + ..moveTo(size.x - 30, 0) |
49 | + ..lineTo(size.x - 110, 50) | ||
50 | + ..lineTo(size.x - 150, 0) | ||
47 | ..fillPath(); | 51 | ..fillPath(); |
48 | - | ||
49 | - super.paint(child, context); | ||
50 | - } | 52 | + }, |
53 | + ), | ||
54 | + ); | ||
55 | + }, | ||
56 | + ); | ||
51 | } | 57 | } |
52 | 58 | ||
53 | class Block extends StatelessWidget { | 59 | class Block extends StatelessWidget { |
-
Please register or login to post a comment