-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamplePDF.dart
More file actions
179 lines (164 loc) · 5.41 KB
/
Copy pathExamplePDF.dart
File metadata and controls
179 lines (164 loc) · 5.41 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
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'dart:io';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';
import 'package:flutter/services.dart' show rootBundle;
Future pdfInvoiceDownload(
BuildContext context,
String? title,
String? equipamento,
String? implemento,
String? setor,
String? local,
String? responsavel,
String? status,
List<String>? servicos,
List<String>? agente,
List<String>? epis,
) async {
// null safety
title = title ?? '';
equipamento = equipamento ?? '';
implemento = implemento ?? '';
setor = setor ?? '';
local = local ?? '';
responsavel = responsavel ?? '';
status = status ?? '';
servicos = servicos ?? [''];
agente = agente ?? [''];
epis = epis ?? [''];
final pdf = pw.Document();
// add network image
final netImage = await networkImage('https://www.nfet.net/nfet.jpg');
// add asset image, IMPORTANT! Using assets will not work in Test/Run mode you can only test it using Web Publishing mode or using an actual device!
/*final bytes =
(await rootBundle.load('assets/images/demo.png')).buffer.asUint8List();
final image = pw.MemoryImage(bytes);*/
pdf.addPage(pw.Page(
theme: pw.ThemeData.withFont(
base: await PdfGoogleFonts.varelaRoundRegular(),
bold: await PdfGoogleFonts.varelaRoundRegular(),
icons: await PdfGoogleFonts.materialIcons(),
),
pageFormat: PdfPageFormat.a4,
build: (pw.Context context) {
return pw.Column(children: [
pw.Text(title ?? '',
style: const pw.TextStyle(
color: PdfColors.cyan,
fontSize: 40,
)),
pw.Divider(thickness: 4),
pw.SizedBox(height: 10),
//equipamento
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.Icon(pw.IconData(0xea79), size: 10),
pw.SizedBox(width: 10),
pw.Text('Equipamento: ' + (equipamento ?? ''))
],
),
//implemento
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.Icon(pw.IconData(0xef3d), size: 10),
pw.SizedBox(width: 10),
pw.Text('Implemento: ' + (implemento ?? ''))
],
),
//setor
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.Icon(pw.IconData(0xe0b8), size: 10),
pw.SizedBox(width: 10),
pw.Text('Setor: ' + (setor ?? ''))
],
),
//local
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.Icon(pw.IconData(0xe55e), size: 10),
pw.SizedBox(width: 10),
pw.Text('Local: ' + (local ?? ''))
],
),
//responsável
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.Icon(pw.IconData(0xe7fd), size: 10),
pw.SizedBox(width: 10),
pw.Text('Responsável: ' + (responsavel ?? ''))
],
),
pw.Container(height: 10),
//status
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.SizedBox(width: 10),
pw.Text('Status: ' + (status ?? ''))
],
),
pw.Divider(thickness: 2),
//servicos
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.SizedBox(width: 10),
pw.Container(
child: pw.Text(
'Serviços: ' + (servicos.toString() ?? ''),
softWrap: true,
),
width: 450)
],
),
pw.Container(height: 20),
//agente
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.SizedBox(width: 10),
pw.Container(
child: pw.Text(
'Agentes Associados: ' + (agente.toString() ?? ''),
softWrap: true,
),
width: 450)
],
),
pw.Container(height: 20),
//EPIs
pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: [
pw.SizedBox(width: 10),
pw.Container(
child: pw.Text(
'EPIs: ' + (epis.toString() ?? ''),
softWrap: true,
),
width: 450)
],
),
]);
}));
final pdfSaved = await pdf.save();
await Printing.layoutPdf(onLayout: (PdfPageFormat format) async => pdfSaved);
}
// Set your action name, define your arguments and return parameter,
// and then add the boilerplate code using the button on the right!