Showing
1 changed file
with
33 additions
and
8 deletions
@@ -23,27 +23,32 @@ import 'package:pdf/widgets.dart'; | @@ -23,27 +23,32 @@ import 'package:pdf/widgets.dart'; | ||
23 | import 'package:test/test.dart'; | 23 | import 'package:test/test.dart'; |
24 | 24 | ||
25 | void main() { | 25 | void main() { |
26 | - test('Pdf Widgets', () { | 26 | + Document pdf; |
27 | + TextStyle symbol; | ||
28 | + PdfImage im; | ||
29 | + | ||
30 | + setUpAll(() { | ||
27 | Document.debug = true; | 31 | Document.debug = true; |
28 | 32 | ||
29 | final Uint8List defaultFont = File('open-sans.ttf').readAsBytesSync(); | 33 | final Uint8List defaultFont = File('open-sans.ttf').readAsBytesSync(); |
30 | final Uint8List defaultFontBold = | 34 | final Uint8List defaultFontBold = |
31 | File('open-sans-bold.ttf').readAsBytesSync(); | 35 | File('open-sans-bold.ttf').readAsBytesSync(); |
32 | 36 | ||
33 | - final Document pdf = Document( | 37 | + pdf = Document( |
34 | title: 'Widgets Test', | 38 | title: 'Widgets Test', |
35 | theme: Theme.withFont( | 39 | theme: Theme.withFont( |
36 | base: Font.ttf(defaultFont.buffer.asByteData()), | 40 | base: Font.ttf(defaultFont.buffer.asByteData()), |
37 | bold: Font.ttf(defaultFontBold.buffer.asByteData()), | 41 | bold: Font.ttf(defaultFontBold.buffer.asByteData()), |
38 | )); | 42 | )); |
39 | 43 | ||
40 | - final TextStyle symbol = TextStyle(font: Font.zapfDingbats()); | 44 | + symbol = TextStyle(font: Font.zapfDingbats()); |
41 | 45 | ||
42 | final List<int> imData = zlib.decode(base64.decode( | 46 | final List<int> imData = zlib.decode(base64.decode( |
43 | 'eJz7//8/w388uOTCT6a4Ez96Q47++I+OI479mEVALyNU7z9seuNP/mAm196Ekz8YR+0dWHtBmJC9S+7/Zog89iMIKLYaHQPVJGLTD7MXpDfq+I9goNhPdPPDjv3YlnH6Jye6+2H21l/6yeB/4HsSDr1bQXrRwq8HqHcGyF6QXp9933N0tn/7Y7vn+/9gLPaih0PDlV9MIAzVm6ez7dsfzW3f/oMwzAx0e7FhoJutdbcj9MKw9frnL2J2POfBpxeEg478YLba/X0Wsl6lBXf+s0bP/s8ePXeWePJCvPEJNYMRZIYWSO/cq/9Z/Nv+M4bO+M8YDjFDJGkhzvSE7A6jRTdnsQR2wfXCMLHuMC5byyidvGgWE5JeZDOIcYdR+TpmkBno+mFmAAC+DGhl')); | 47 | 'eJz7//8/w388uOTCT6a4Ez96Q47++I+OI479mEVALyNU7z9seuNP/mAm196Ekz8YR+0dWHtBmJC9S+7/Zog89iMIKLYaHQPVJGLTD7MXpDfq+I9goNhPdPPDjv3YlnH6Jye6+2H21l/6yeB/4HsSDr1bQXrRwq8HqHcGyF6QXp9933N0tn/7Y7vn+/9gLPaih0PDlV9MIAzVm6ez7dsfzW3f/oMwzAx0e7FhoJutdbcj9MKw9frnL2J2POfBpxeEg478YLba/X0Wsl6lBXf+s0bP/s8ePXeWePJCvPEJNYMRZIYWSO/cq/9Z/Nv+M4bO+M8YDjFDJGkhzvSE7A6jRTdnsQR2wfXCMLHuMC5byyidvGgWE5JeZDOIcYdR+TpmkBno+mFmAAC+DGhl')); |
44 | - final PdfImage im = | ||
45 | - PdfImage(pdf.document, image: imData, width: 16, height: 20); | 48 | + im = PdfImage(pdf.document, image: imData, width: 16, height: 20); |
49 | + }); | ||
46 | 50 | ||
51 | + test('Pdf Widgets page 1', () { | ||
47 | pdf.addPage(Page( | 52 | pdf.addPage(Page( |
48 | pageFormat: const PdfPageFormat(400, 400), | 53 | pageFormat: const PdfPageFormat(400, 400), |
49 | margin: const EdgeInsets.all(10), | 54 | margin: const EdgeInsets.all(10), |
@@ -63,8 +68,14 @@ void main() { | @@ -63,8 +68,14 @@ void main() { | ||
63 | textScaleFactor: 2, textAlign: TextAlign.center)), | 68 | textScaleFactor: 2, textAlign: TextAlign.center)), |
64 | Align( | 69 | Align( |
65 | alignment: Alignment.topLeft, | 70 | alignment: Alignment.topLeft, |
66 | - child: | ||
67 | - Link(destination: 'anchor', child: Text('Left align'))), | 71 | + child: Link( |
72 | + destination: 'anchor', | ||
73 | + child: Text( | ||
74 | + 'Internal link', | ||
75 | + style: TextStyle( | ||
76 | + color: PdfColors.blue, | ||
77 | + ), | ||
78 | + ))), | ||
68 | Padding(padding: const EdgeInsets.all(5)), | 79 | Padding(padding: const EdgeInsets.all(5)), |
69 | Row( | 80 | Row( |
70 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, | 81 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
@@ -98,7 +109,9 @@ void main() { | @@ -98,7 +109,9 @@ void main() { | ||
98 | .copyWith(font: Font.timesBoldItalic()), | 109 | .copyWith(font: Font.timesBoldItalic()), |
99 | textScaleFactor: 3)), | 110 | textScaleFactor: 3)), |
100 | ]))); | 111 | ]))); |
112 | + }); | ||
101 | 113 | ||
114 | + test('Pdf Widgets page 2', () { | ||
102 | pdf.addPage(Page( | 115 | pdf.addPage(Page( |
103 | pageFormat: const PdfPageFormat(400, 400), | 116 | pageFormat: const PdfPageFormat(400, 400), |
104 | margin: const EdgeInsets.all(10), | 117 | margin: const EdgeInsets.all(10), |
@@ -111,7 +124,9 @@ void main() { | @@ -111,7 +124,9 @@ void main() { | ||
111 | padding: const EdgeInsets.all(10), | 124 | padding: const EdgeInsets.all(10), |
112 | children: List<Widget>.generate( | 125 | children: List<Widget>.generate( |
113 | 9, (int n) => FittedBox(child: Text('${n + 1}'))))))); | 126 | 9, (int n) => FittedBox(child: Text('${n + 1}'))))))); |
127 | + }); | ||
114 | 128 | ||
129 | + test('Pdf Widgets page 3', () { | ||
115 | pdf.addPage(MultiPage( | 130 | pdf.addPage(MultiPage( |
116 | pageFormat: const PdfPageFormat(400, 200), | 131 | pageFormat: const PdfPageFormat(400, 200), |
117 | margin: const EdgeInsets.all(10), | 132 | margin: const EdgeInsets.all(10), |
@@ -150,7 +165,9 @@ void main() { | @@ -150,7 +165,9 @@ void main() { | ||
150 | ]), | 165 | ]), |
151 | Anchor(name: 'anchor', child: Text('Anchor')), | 166 | Anchor(name: 'anchor', child: Text('Anchor')), |
152 | ])); | 167 | ])); |
168 | + }); | ||
153 | 169 | ||
170 | + test('Pdf Widgets page 4', () { | ||
154 | pdf.addPage(Page( | 171 | pdf.addPage(Page( |
155 | pageFormat: const PdfPageFormat(400, 200), | 172 | pageFormat: const PdfPageFormat(400, 200), |
156 | margin: const EdgeInsets.all(10), | 173 | margin: const EdgeInsets.all(10), |
@@ -193,7 +210,13 @@ void main() { | @@ -193,7 +210,13 @@ void main() { | ||
193 | right: 10, | 210 | right: 10, |
194 | bottom: 10, | 211 | bottom: 10, |
195 | child: UrlLink( | 212 | child: UrlLink( |
196 | - child: Text('dart_pdf'), | 213 | + child: Text( |
214 | + 'https://github.com/DavBfr/dart_pdf/', | ||
215 | + style: TextStyle( | ||
216 | + color: PdfColors.grey, | ||
217 | + fontSize: 8, | ||
218 | + ), | ||
219 | + ), | ||
197 | destination: 'https://github.com/DavBfr/dart_pdf/')), | 220 | destination: 'https://github.com/DavBfr/dart_pdf/')), |
198 | Positioned( | 221 | Positioned( |
199 | left: 10, | 222 | left: 10, |
@@ -213,7 +236,9 @@ void main() { | @@ -213,7 +236,9 @@ void main() { | ||
213 | strokeWidth: 15), | 236 | strokeWidth: 15), |
214 | ]))) | 237 | ]))) |
215 | ]))); | 238 | ]))); |
239 | + }); | ||
216 | 240 | ||
241 | + tearDownAll(() { | ||
217 | final File file = File('widgets.pdf'); | 242 | final File file = File('widgets.pdf'); |
218 | file.writeAsBytesSync(pdf.save()); | 243 | file.writeAsBytesSync(pdf.save()); |
219 | }); | 244 | }); |
-
Please register or login to post a comment