resume.dart
11.1 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'dart:async';
import 'dart:math';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
const PdfColor green = PdfColor.fromInt(0xff9ce5d0);
const PdfColor lightGreen = PdfColor.fromInt(0xffcdf1e7);
const sep = 120.0;
Future<Uint8List> generateResume(PdfPageFormat format) async {
final doc = pw.Document(title: 'My Résumé', author: 'David PHAM-VAN');
final profileImage = pw.MemoryImage(
(await rootBundle.load('assets/profile.jpg')).buffer.asUint8List(),
);
final pageTheme = await _myPageTheme(format);
doc.addPage(
pw.MultiPage(
pageTheme: pageTheme,
build: (pw.Context context) => [
pw.Partitions(
children: [
pw.Partition(
child: pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Container(
padding: const pw.EdgeInsets.only(left: 30, bottom: 20),
child: pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Text('Parnella Charlesbois',
textScaleFactor: 2,
style: pw.Theme.of(context)
.defaultTextStyle
.copyWith(fontWeight: pw.FontWeight.bold)),
pw.Padding(padding: const pw.EdgeInsets.only(top: 10)),
pw.Text('Electrotyper',
textScaleFactor: 1.2,
style: pw.Theme.of(context)
.defaultTextStyle
.copyWith(
fontWeight: pw.FontWeight.bold,
color: green)),
pw.Padding(padding: const pw.EdgeInsets.only(top: 20)),
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: <pw.Widget>[
pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Text('568 Port Washington Road'),
pw.Text('Nordegg, AB T0M 2H0'),
pw.Text('Canada, ON'),
],
),
pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Text('+1 403-721-6898'),
_UrlText('p.charlesbois@yahoo.com',
'mailto:p.charlesbois@yahoo.com'),
_UrlText(
'wholeprices.ca', 'https://wholeprices.ca'),
],
),
pw.Padding(padding: pw.EdgeInsets.zero)
],
),
],
),
),
_Category(title: 'Work Experience'),
_Block(
title: 'Tour bus driver',
icon: const pw.IconData(0xe530)),
_Block(
title: 'Logging equipment operator',
icon: const pw.IconData(0xe30d)),
_Block(title: 'Foot doctor', icon: const pw.IconData(0xe3f3)),
_Block(
title: 'Unicorn trainer',
icon: const pw.IconData(0xf0cf)),
_Block(
title: 'Chief chatter', icon: const pw.IconData(0xe0ca)),
pw.SizedBox(height: 20),
_Category(title: 'Education'),
_Block(title: 'Bachelor Of Commerce'),
_Block(title: 'Bachelor Interior Design'),
],
),
),
pw.Partition(
width: sep,
child: pw.Column(
children: [
pw.Container(
height: pageTheme.pageFormat.availableHeight,
child: pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.center,
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
children: <pw.Widget>[
pw.ClipOval(
child: pw.Container(
width: 100,
height: 100,
color: lightGreen,
child: pw.Image(profileImage),
),
),
pw.Column(children: <pw.Widget>[
_Percent(size: 60, value: .7, title: pw.Text('Word')),
_Percent(
size: 60, value: .4, title: pw.Text('Excel')),
]),
pw.BarcodeWidget(
data: 'Parnella Charlesbois',
width: 60,
height: 60,
barcode: pw.Barcode.qrCode(),
),
],
),
),
],
),
)
],
),
],
),
);
return doc.save();
}
Future<pw.PageTheme> _myPageTheme(PdfPageFormat format) async {
final bgShape = await rootBundle.loadString('assets/resume.svg');
format = format.applyMargin(
left: 2.0 * PdfPageFormat.cm,
top: 4.0 * PdfPageFormat.cm,
right: 2.0 * PdfPageFormat.cm,
bottom: 2.0 * PdfPageFormat.cm);
return pw.PageTheme(
pageFormat: format,
theme: pw.ThemeData.withFont(
base: pw.Font.ttf(await rootBundle.load('assets/open-sans.ttf')),
bold: pw.Font.ttf(await rootBundle.load('assets/open-sans-bold.ttf')),
icons: pw.Font.ttf(await rootBundle.load('assets/material.ttf')),
),
buildBackground: (pw.Context context) {
return pw.FullPage(
ignoreMargins: true,
child: pw.Stack(
children: [
pw.Positioned(
child: pw.SvgImage(svg: bgShape),
left: 0,
top: 0,
),
pw.Positioned(
child: pw.Transform.rotate(
angle: pi, child: pw.SvgImage(svg: bgShape)),
right: 0,
bottom: 0,
),
],
),
);
},
);
}
class _Block extends pw.StatelessWidget {
_Block({this.title, this.icon});
final String title;
final pw.IconData icon;
@override
pw.Widget build(pw.Context context) {
return pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Container(
width: 6,
height: 6,
margin: const pw.EdgeInsets.only(top: 2.5, left: 2, right: 5),
decoration: const pw.BoxDecoration(
color: green, shape: pw.BoxShape.circle),
),
pw.Text(title,
style: pw.Theme.of(context)
.defaultTextStyle
.copyWith(fontWeight: pw.FontWeight.bold)),
pw.Spacer(),
if (icon != null) pw.Icon(icon, color: lightGreen, size: 18),
]),
pw.Container(
decoration: const pw.BoxDecoration(
border: pw.Border(left: pw.BorderSide(color: green, width: 2))),
padding: const pw.EdgeInsets.only(left: 10, top: 5, bottom: 5),
margin: const pw.EdgeInsets.only(left: 5),
child: pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Lorem(length: 20),
]),
),
]);
}
}
class _Category extends pw.StatelessWidget {
_Category({this.title});
final String title;
@override
pw.Widget build(pw.Context context) {
return pw.Container(
decoration: const pw.BoxDecoration(
color: lightGreen,
borderRadius: pw.BorderRadius.all(pw.Radius.circular(6)),
),
margin: const pw.EdgeInsets.only(bottom: 10, top: 20),
padding: const pw.EdgeInsets.fromLTRB(10, 7, 10, 4),
child: pw.Text(title, textScaleFactor: 1.5));
}
}
class _Percent extends pw.StatelessWidget {
_Percent({
@required this.size,
@required this.value,
this.title,
this.fontSize = 1.2,
this.color = green,
this.backgroundColor = PdfColors.grey300,
this.strokeWidth = 5,
}) : assert(size != null);
final double size;
final double value;
final pw.Widget title;
final double fontSize;
final PdfColor color;
final PdfColor backgroundColor;
final double strokeWidth;
@override
pw.Widget build(pw.Context context) {
final widgets = <pw.Widget>[
pw.Container(
width: size,
height: size,
child: pw.Stack(
alignment: pw.Alignment.center,
fit: pw.StackFit.expand,
children: <pw.Widget>[
pw.Center(
child: pw.Text(
'${(value * 100).round().toInt()}%',
textScaleFactor: fontSize,
),
),
pw.CircularProgressIndicator(
value: value,
backgroundColor: backgroundColor,
color: color,
strokeWidth: strokeWidth,
),
],
),
)
];
if (title != null) {
widgets.add(title);
}
return pw.Column(children: widgets);
}
}
class _UrlText extends pw.StatelessWidget {
_UrlText(this.text, this.url);
final String text;
final String url;
@override
pw.Widget build(pw.Context context) {
return pw.UrlLink(
destination: url,
child: pw.Text(text,
style: const pw.TextStyle(
decoration: pw.TextDecoration.underline,
color: PdfColors.blue,
)),
);
}
}