document.dart
7.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import 'dart:async';
import 'package:flutter/widgets.dart' as fw;
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
import 'package:printing/printing.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) {
context.canvas
..setColor(lightGreen)
..moveTo(0, pageFormat.height)
..lineTo(0, pageFormat.height - 230)
..lineTo(60, pageFormat.height)
..fillPath()
..setColor(green)
..moveTo(0, pageFormat.height)
..lineTo(0, pageFormat.height - 100)
..lineTo(100, pageFormat.height)
..fillPath()
..setColor(lightGreen)
..moveTo(30, pageFormat.height)
..lineTo(110, pageFormat.height - 50)
..lineTo(150, pageFormat.height)
..fillPath()
..moveTo(pageFormat.width, 0)
..lineTo(pageFormat.width, 230)
..lineTo(pageFormat.width - 60, 0)
..fillPath()
..setColor(green)
..moveTo(pageFormat.width, 0)
..lineTo(pageFormat.width, 100)
..lineTo(pageFormat.width - 100, 0)
..fillPath()
..setColor(lightGreen)
..moveTo(pageFormat.width - 30, 0)
..lineTo(pageFormat.width - 110, 50)
..lineTo(pageFormat.width - 150, 0)
..fillPath();
super.paint(child, context);
}
}
class Block extends StatelessWidget {
Block({this.title});
final String title;
@override
Widget build(Context context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
Container(
width: 6,
height: 6,
margin: const EdgeInsets.only(top: 2.5, left: 2, right: 5),
decoration:
const BoxDecoration(color: green, shape: BoxShape.circle),
),
Text(title, style: Theme.of(context).defaultTextStyleBold),
]),
Container(
decoration: const BoxDecoration(
border: BoxBorder(left: true, color: green, width: 2)),
padding: const EdgeInsets.only(left: 10, top: 5, bottom: 5),
margin: const EdgeInsets.only(left: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Lorem(length: 20),
]),
),
]);
}
}
class Category extends StatelessWidget {
Category({this.title});
final String title;
@override
Widget build(Context context) {
return Container(
decoration: const BoxDecoration(color: lightGreen, borderRadius: 6),
margin: const EdgeInsets.only(bottom: 10, top: 20),
padding: const EdgeInsets.fromLTRB(10, 7, 10, 4),
child: Text(title, textScaleFactor: 1.5));
}
}
Future<PdfDocument> generateDocument(PdfPageFormat format) async {
final PdfDoc pdf = PdfDoc();
final PdfImage profileImage = await pdfImageFromImageProvider(
pdf: pdf.document,
image: const fw.NetworkImage(
'https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mp&s=200'),
onError: (dynamic exception, StackTrace stackTrace) {
print('error');
});
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),
build: (Context context) => Row(children: <Widget>[
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
padding: const EdgeInsets.only(left: 30, bottom: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Parnella Charlesbois',
textScaleFactor: 2.0,
style: Theme.of(context).defaultTextStyleBold),
Padding(padding: const EdgeInsets.only(top: 10)),
Text('Electrotyper',
textScaleFactor: 1.2,
style: Theme.of(context)
.defaultTextStyleBold
.copyWith(color: green)),
Padding(padding: const EdgeInsets.only(top: 20)),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text('568 Port Washington Road'),
Text('Nordegg, AB T0M 2H0'),
Text('Canada, ON'),
]),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text('+1 403-721-6898'),
Text('p.charlesbois@yahoo.com'),
Text('wholeprices.ca')
]),
Padding(padding: EdgeInsets.zero)
]),
])),
Category(title: 'Work Experience'),
Block(title: 'Tour bus driver'),
Block(title: 'Logging equipment operator'),
Block(title: 'Foot doctor'),
Category(title: 'Education'),
Block(title: 'Bachelor Of Commerce'),
Block(title: 'Bachelor Interior Design'),
])),
Container(
height: double.infinity,
width: 10,
decoration: const BoxDecoration(
border: BoxBorder(left: true, color: green, width: 2)),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ClipOval(
child: Container(
width: 100,
height: 100,
color: lightGreen,
child: profileImage == null
? Container()
: Image(profileImage)))
])
]),
));
return pdf.document;
}