Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
dart_pdf
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
David PHAM-VAN
2020-04-19 14:51:24 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
98991b4dc9541bd8c251e302217c59c3b755a02c
98991b4d
1 parent
a21b2375
Use the Barcode library to generate QR-Codes
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
159 deletions
pdf/CHANGELOG.md
pdf/lib/widgets.dart
pdf/lib/widgets/qrcode.dart
pdf/pubspec.yaml
pdf/test/widget_barcode_test.dart
printing/example/lib/document.dart
test/golden/widgets-barcode.pdf
pdf/CHANGELOG.md
View file @
98991b4
# Changelog
## 1.6.2
-
Use the Barcode library to generate QR-Codes
## 1.6.1
-
Fix Image width and height attributes
...
...
pdf/lib/widgets.dart
View file @
98991b4
...
...
@@ -23,9 +23,10 @@ import 'dart:typed_data';
import
'package:barcode/barcode.dart'
;
import
'package:meta/meta.dart'
;
import
'package:pdf/pdf.dart'
;
import
'package:qr/qr.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
export
'package:barcode/barcode.dart'
;
part
'widgets/annotations.dart'
;
part
'widgets/barcode.dart'
;
part
'widgets/basic.dart'
;
...
...
pdf/lib/widgets/qrcode.dart
View file @
98991b4
...
...
@@ -20,98 +20,12 @@ part of widget;
typedef
QrError
=
void
Function
(
dynamic
error
);
class
_QrCodeWidget
extends
Widget
{
_QrCodeWidget
({
@required
String
data
,
this
.
version
,
this
.
errorCorrectionLevel
,
this
.
color
,
this
.
onError
,
this
.
gapless
=
false
,
})
:
assert
(
data
!=
null
),
_qr
=
version
==
null
?
QrCode
.
fromData
(
data:
data
,
errorCorrectLevel:
errorCorrectionLevel
,
)
:
QrCode
(
version
,
errorCorrectionLevel
,
)
{
// configure and make the QR code data
try
{
if
(
version
!=
null
)
{
_qr
.
addData
(
data
);
}
_qr
.
make
();
}
catch
(
ex
)
{
if
(
onError
!=
null
)
{
_hasError
=
true
;
onError
(
ex
);
}
}
}
@override
void
layout
(
Context
context
,
BoxConstraints
constraints
,
{
bool
parentUsesSize
=
false
})
{
box
=
PdfRect
.
fromPoints
(
PdfPoint
.
zero
,
constraints
.
biggest
);
}
/// the qr code version
final
int
version
;
/// the qr code error correction level
final
int
errorCorrectionLevel
;
/// the color of the dark squares
final
PdfColor
color
;
final
QrError
onError
;
final
bool
gapless
;
// our qr code data
final
QrCode
_qr
;
bool
_hasError
=
false
;
@override
void
paint
(
Context
context
)
{
super
.
paint
(
context
);
if
(
_hasError
)
{
return
;
}
final
double
shortestSide
=
box
.
width
<
box
.
height
?
box
.
width
:
box
.
height
;
assert
(
shortestSide
>
0
);
context
.
canvas
.
setFillColor
(
color
);
final
double
squareSize
=
shortestSide
/
_qr
.
moduleCount
.
toDouble
();
final
int
pxAdjustValue
=
gapless
?
1
:
0
;
for
(
int
x
=
0
;
x
<
_qr
.
moduleCount
;
x
++)
{
for
(
int
y
=
0
;
y
<
_qr
.
moduleCount
;
y
++)
{
if
(
_qr
.
isDark
(
y
,
x
))
{
context
.
canvas
.
drawRect
(
box
.
left
+
x
*
squareSize
,
box
.
top
-
(
y
+
1
)
*
squareSize
,
squareSize
+
pxAdjustValue
,
squareSize
+
pxAdjustValue
,
);
}
}
}
context
.
canvas
.
fillPath
();
}
}
@Deprecated
(
'Use BarcodeWidget instead'
)
class
QrCodeWidget
extends
StatelessWidget
{
QrCodeWidget
({
@required
this
.
data
,
this
.
version
,
this
.
errorCorrectionLevel
=
QrErrorCorrectLevel
.
L
,
this
.
errorCorrectionLevel
=
BarcodeQRCorrectionLevel
.
low
,
this
.
color
=
PdfColors
.
black
,
this
.
backgroundColor
,
this
.
decoration
,
...
...
@@ -129,7 +43,7 @@ class QrCodeWidget extends StatelessWidget {
final
int
version
;
/// the qr code error correction level
final
int
errorCorrectionLevel
;
final
BarcodeQRCorrectionLevel
errorCorrectionLevel
;
/// the color of the dark squares
final
PdfColor
color
;
...
...
@@ -150,41 +64,19 @@ class QrCodeWidget extends StatelessWidget {
@override
Widget
build
(
Context
context
)
{
Widget
qrcode
=
AspectRatio
(
aspectRatio:
1.0
,
child:
_QrCodeWidget
(
data:
data
,
version:
version
,
errorCorrectionLevel:
errorCorrectionLevel
,
color:
color
,
onError:
onError
,
gapless:
gapless
,
));
if
(
padding
!=
null
)
{
qrcode
=
Padding
(
padding:
padding
,
child:
qrcode
);
}
if
(
decoration
!=
null
)
{
qrcode
=
DecoratedBox
(
decoration:
decoration
,
child:
qrcode
,
);
}
else
if
(
backgroundColor
!=
null
)
{
qrcode
=
DecoratedBox
(
decoration:
BoxDecoration
(
color:
backgroundColor
),
child:
qrcode
,
);
}
if
(
size
!=
null
)
{
qrcode
=
SizedBox
(
width:
size
,
height:
size
,
child:
qrcode
);
}
if
(
margin
!=
null
)
{
qrcode
=
Padding
(
padding:
margin
,
child:
qrcode
);
}
return
qrcode
;
return
BarcodeWidget
(
barcode:
Barcode
.
qrCode
(
typeNumber:
version
,
errorCorrectLevel:
errorCorrectionLevel
,
),
data:
data
,
backgroundColor:
backgroundColor
,
color:
color
,
decoration:
decoration
,
width:
size
,
height:
size
,
margin:
margin
,
padding:
padding
,
);
}
}
...
...
pdf/pubspec.yaml
View file @
98991b4
...
...
@@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
homepage
:
https://github.com/DavBfr/dart_pdf/tree/master/pdf
repository
:
https://github.com/DavBfr/dart_pdf
issue_tracker
:
https://github.com/DavBfr/dart_pdf/issues
version
:
1.6.
1
version
:
1.6.
2
environment
:
sdk
:
"
>=2.3.0
<3.0.0"
...
...
@@ -15,8 +15,7 @@ dependencies:
utf
:
^0.9.0
crypto
:
^2.0.6
archive
:
^2.0.10
qr
:
^1.2.0
barcode
:
^1.5.0
barcode
:
^1.7.0
image
:
^2.1.4
dev_dependencies
:
...
...
pdf/test/widget_barcode_test.dart
View file @
98991b4
...
...
@@ -18,14 +18,17 @@
import
'dart:io'
;
import
'package:barcode/barcode.dart'
;
import
'package:pdf/pdf.dart'
;
import
'package:pdf/widgets.dart'
;
import
'package:test/test.dart'
;
Document
pdf
;
Widget
barcode
(
Barcode
barcode
,
String
data
,
{
double
width
=
200
})
{
Widget
barcode
(
Barcode
barcode
,
String
data
,
{
double
width
=
200
,
double
height
=
80
,
})
{
return
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
<
Widget
>[
...
...
@@ -42,7 +45,7 @@ Widget barcode(Barcode barcode, String data, {double width = 200}) {
barcode:
barcode
,
data:
data
,
width:
width
,
height:
80
,
height:
height
,
margin:
const
EdgeInsets
.
symmetric
(
vertical:
20
),
),
),
...
...
@@ -72,34 +75,13 @@ void main() {
barcode
(
Barcode
.
ean2
(),
'44'
,
width:
40
),
barcode
(
Barcode
.
ean5
(),
'30897'
,
width:
60
),
barcode
(
Barcode
.
itf14
(),
'2578639587234'
),
barcode
(
Barcode
.
telepen
(),
'Telepen'
),
barcode
(
Barcode
.
qrCode
(),
'QR-Code!'
,
width:
120
,
height:
120
),
],
),
);
});
test
(
'QrCode Widgets'
,
()
{
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
QrCodeWidget
(
data:
'HELLO 123'
,
size:
200
,
padding:
const
EdgeInsets
.
all
(
20
),
margin:
const
EdgeInsets
.
all
(
20
),
decoration:
const
BoxDecoration
(
borderRadius:
20
,
color:
PdfColors
.
white
,
border:
BoxBorder
(
color:
PdfColors
.
blue
,
top:
true
,
bottom:
true
,
left:
true
,
right:
true
,
)),
),
),
);
});
tearDownAll
(()
{
final
File
file
=
File
(
'widgets-barcode.pdf'
);
file
.
writeAsBytesSync
(
pdf
.
save
());
...
...
printing/example/lib/document.dart
View file @
98991b4
...
...
@@ -100,7 +100,12 @@ Future<pw.Document> generateDocument(PdfPageFormat format) async {
Percent
(
size:
60
,
value:
.
7
,
title:
pw
.
Text
(
'Word'
)),
Percent
(
size:
60
,
value:
.
4
,
title:
pw
.
Text
(
'Excel'
)),
]),
pw
.
QrCodeWidget
(
data:
'Parnella Charlesbois'
,
size:
60
),
pw
.
BarcodeWidget
(
data:
'Parnella Charlesbois'
,
width:
60
,
height:
60
,
barcode:
pw
.
Barcode
.
qrCode
(),
),
],
)
]),
...
...
test/golden/widgets-barcode.pdf
View file @
98991b4
No preview for this file type
Please
register
or
login
to post a comment