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
2019-12-27 10:02:02 -0500
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b94f15d5f265f9870f4826d7fa0b64a18477b912
b94f15d5
1 parent
359a0387
Use Barcode stable API
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
134 additions
and
47 deletions
pdf/CHANGELOG.md
pdf/lib/widgets.dart
pdf/lib/widgets/barcode.dart
pdf/pubspec.yaml
pdf/test/widget_barcode_test.dart
test/golden/widgets-barcode.pdf
pdf/CHANGELOG.md
View file @
b94f15d
# Changelog
## 1.3.29
-
Use Barcode stable API
## 1.3.28
-
Add Barcode Widget
...
...
pdf/lib/widgets.dart
View file @
b94f15d
...
...
@@ -20,10 +20,10 @@ import 'dart:collection';
import
'dart:math'
as
math
;
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:barcode/barcode.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
part
'widgets/annotations.dart'
;
...
...
pdf/lib/widgets/barcode.dart
View file @
b94f15d
...
...
@@ -23,6 +23,8 @@ class _BarcodeWidget extends Widget {
@required
this
.
data
,
this
.
barcode
,
this
.
color
=
PdfColors
.
black
,
this
.
drawText
,
this
.
textStyle
,
});
/// the barcode data
...
...
@@ -32,6 +34,10 @@ class _BarcodeWidget extends Widget {
final
PdfColor
color
;
final
bool
drawText
;
final
TextStyle
textStyle
;
@override
void
layout
(
Context
context
,
BoxConstraints
constraints
,
{
bool
parentUsesSize
=
false
})
{
...
...
@@ -42,30 +48,87 @@ class _BarcodeWidget extends Widget {
void
paint
(
Context
context
)
{
super
.
paint
(
context
);
final
BarcodeDraw
draw
=
barcode
.
draw
;
if
(
draw
is
_BarcodeDraw
)
{
draw
..
canvas
=
context
.
canvas
..
left
=
box
.
left
..
top
=
box
.
top
;
final
List
<
BarcodeText
>
textList
=
<
BarcodeText
>[];
for
(
BarcodeElement
element
in
barcode
.
make
(
data
,
width:
box
.
width
,
height:
box
.
height
,
drawText:
drawText
,
fontHeight:
textStyle
.
fontSize
,
))
{
if
(
element
is
BarcodeBar
)
{
if
(
element
.
black
)
{
context
.
canvas
.
drawRect
(
box
.
left
+
element
.
left
,
box
.
top
+
element
.
top
-
element
.
height
,
element
.
width
,
element
.
height
,
);
}
}
else
if
(
element
is
BarcodeText
)
{
textList
.
add
(
element
);
}
}
context
.
canvas
.
setFillColor
(
color
);
barcode
.
make
(
data
,
box
.
width
,
box
.
height
);
context
.
canvas
.
fillPath
();
}
}
context
.
canvas
..
setFillColor
(
color
)
..
fillPath
();
class
_BarcodeDraw
extends
BarcodeDraw
{
PdfGraphics
canvas
;
double
left
;
double
top
;
if
(
drawText
)
{
final
PdfFont
font
=
textStyle
.
font
.
getFont
(
context
);
for
(
BarcodeText
text
in
textList
)
{
final
PdfFontMetrics
metrics
=
font
.
stringMetrics
(
text
.
text
);
final
double
left
=
text
.
left
+
box
.
left
+
(
text
.
width
-
metrics
.
width
*
text
.
height
)
/
2
;
final
double
top
=
box
.
top
-
text
.
top
-
metrics
.
descent
*
textStyle
.
fontSize
-
text
.
height
;
context
.
canvas
..
setFillColor
(
textStyle
.
color
)
..
drawString
(
font
,
text
.
height
,
text
.
text
,
left
,
top
,
);
}
}
}
@override
void
fillRect
(
double
left
,
double
top
,
double
width
,
double
height
,
bool
black
)
{
if
(
black
)
{
canvas
.
drawRect
(
this
.
left
+
left
,
this
.
top
+
top
-
height
,
width
,
height
);
void
debugPaint
(
Context
context
)
{
super
.
debugPaint
(
context
);
if
(
drawText
)
{
for
(
BarcodeElement
element
in
barcode
.
make
(
data
,
width:
box
.
width
,
height:
box
.
height
,
drawText:
drawText
,
fontHeight:
textStyle
.
fontSize
,
))
{
if
(
element
is
BarcodeText
)
{
context
.
canvas
.
drawRect
(
box
.
x
+
element
.
left
,
box
.
y
+
box
.
height
-
element
.
top
-
element
.
height
,
element
.
width
,
element
.
height
,
);
}
}
context
.
canvas
..
setStrokeColor
(
PdfColors
.
blue
)
..
setLineWidth
(
1
)
..
strokePath
();
}
}
}
...
...
@@ -110,31 +173,24 @@ class BarcodeWidget extends StatelessWidget {
@override
Widget
build
(
Context
context
)
{
final
TextStyle
_textStyle
=
textStyle
??
TextStyle
(
font:
Font
.
courier
());
final
TextStyle
defaultstyle
=
Theme
.
of
(
context
).
defaultTextStyle
.
copyWith
(
font:
Font
.
courier
(),
fontNormal:
Font
.
courier
(),
fontBold:
Font
.
courierBold
(),
fontItalic:
Font
.
courierOblique
(),
fontBoldItalic:
Font
.
courierBoldOblique
(),
lineSpacing:
1
,
);
final
TextStyle
_textStyle
=
defaultstyle
.
merge
(
textStyle
);
Widget
barcode
=
_BarcodeWidget
(
data:
data
,
color:
color
,
barcode:
Barcode
.
fromType
(
type:
type
,
draw:
_BarcodeDraw
(),
),
barcode:
Barcode
.
fromType
(
type
),
drawText:
drawText
,
textStyle:
_textStyle
,
);
if
(
drawText
)
{
barcode
=
Column
(
children:
<
Widget
>[
Flexible
(
child:
barcode
),
Text
(
data
,
style:
_textStyle
,
textAlign:
TextAlign
.
center
,
softWrap:
false
,
),
],
);
}
if
(
padding
!=
null
)
{
barcode
=
Padding
(
padding:
padding
,
child:
barcode
);
}
...
...
pdf/pubspec.yaml
View file @
b94f15d
...
...
@@ -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.3.2
8
version
:
1.3.2
9
environment
:
sdk
:
"
>=2.3.0
<3.0.0"
...
...
@@ -16,7 +16,7 @@ dependencies:
crypto
:
^2.0.6
archive
:
^2.0.10
qr
:
^1.2.0
barcode
:
^
0.1
.0
barcode
:
^
1.0
.0
dev_dependencies
:
test
:
...
...
pdf/test/widget_barcode_test.dart
View file @
b94f15d
...
...
@@ -18,6 +18,7 @@
import
'dart:io'
;
import
'package:barcode/barcode.dart'
;
import
'package:pdf/pdf.dart'
;
import
'package:pdf/widgets.dart'
;
import
'package:test/test.dart'
;
...
...
@@ -30,13 +31,36 @@ void main() {
pdf
=
Document
();
});
test
(
'Barcode Widgets
Code39
'
,
()
{
test
(
'Barcode Widgets'
,
()
{
pdf
.
addPage
(
Page
(
build:
(
Context
context
)
=>
BarcodeWidget
(
data:
'HELLO 123'
,
width:
200
,
height:
50
,
MultiPage
(
build:
(
Context
context
)
=>
List
<
Widget
>.
generate
(
BarcodeType
.
values
.
length
,
(
int
index
)
{
return
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
<
Widget
>[
Text
(
BarcodeType
.
values
[
index
].
toString
()),
BarcodeWidget
(
type:
BarcodeType
.
values
[
index
],
data:
'HELLO 123'
,
width:
200
,
height:
50
,
margin:
const
EdgeInsets
.
symmetric
(
vertical:
20
),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
10
,
vertical:
3
),
decoration:
BoxDecoration
(
border:
BoxBorder
(
color:
PdfColors
.
blue
,
top:
true
,
bottom:
true
,
left:
true
,
right:
true
,
)),
),
],
);
},
),
),
);
...
...
test/golden/widgets-barcode.pdf
0 → 100644
View file @
b94f15d
No preview for this file type
Please
register
or
login
to post a comment