David PHAM-VAN

Improve BarcodeWidget

# Changelog
## 1.3.30
- Improve BarcodeWidget
## 1.3.29
- Use Barcode stable API
... ...
... ... @@ -136,7 +136,9 @@ class _BarcodeWidget extends Widget {
class BarcodeWidget extends StatelessWidget {
BarcodeWidget({
@required this.data,
this.type = BarcodeType.Code39,
@Deprecated('Use `Barcode.fromType(type)` instead')
BarcodeType type = BarcodeType.Code39,
Barcode barcode,
this.color = PdfColors.black,
this.backgroundColor,
this.decoration,
... ... @@ -146,12 +148,14 @@ class BarcodeWidget extends StatelessWidget {
this.height,
this.drawText = true,
this.textStyle,
});
}) :
// ignore: deprecated_member_use_from_same_package
barcode = barcode ?? Barcode.fromType(type);
/// the barcode data
final String data;
final BarcodeType type;
final Barcode barcode;
final PdfColor color;
... ... @@ -183,38 +187,38 @@ class BarcodeWidget extends StatelessWidget {
);
final TextStyle _textStyle = defaultstyle.merge(textStyle);
Widget barcode = _BarcodeWidget(
Widget child = _BarcodeWidget(
data: data,
color: color,
barcode: Barcode.fromType(type),
barcode: barcode,
drawText: drawText,
textStyle: _textStyle,
);
if (padding != null) {
barcode = Padding(padding: padding, child: barcode);
child = Padding(padding: padding, child: child);
}
if (decoration != null) {
barcode = DecoratedBox(
child = DecoratedBox(
decoration: decoration,
child: barcode,
child: child,
);
} else if (backgroundColor != null) {
barcode = DecoratedBox(
child = DecoratedBox(
decoration: BoxDecoration(color: backgroundColor),
child: barcode,
child: child,
);
}
if (width != null || height != null) {
barcode = SizedBox(width: width, height: height, child: barcode);
child = SizedBox(width: width, height: height, child: child);
}
if (margin != null) {
barcode = Padding(padding: margin, child: barcode);
child = Padding(padding: margin, child: child);
}
return barcode;
return child;
}
}
... ...
... ... @@ -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.29
version: 1.3.30
environment:
sdk: ">=2.3.0 <3.0.0"
... ...
... ... @@ -25,6 +25,40 @@ import 'package:test/test.dart';
Document pdf;
Widget barcode(Barcode barcode, String data) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Flexible(
fit: FlexFit.tight,
child: Center(
child: Text(barcode.name),
),
),
Flexible(
fit: FlexFit.tight,
child: BarcodeWidget(
barcode: barcode,
data: data,
width: 200,
height: 80,
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,
),
),
),
),
],
);
}
void main() {
setUpAll(() {
Document.debug = true;
... ... @@ -34,34 +68,16 @@ void main() {
test('Barcode Widgets', () {
pdf.addPage(
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,
)),
),
],
);
},
),
build: (Context context) => <Widget>[
barcode(Barcode.code39(), 'CODE 39'),
barcode(Barcode.code93(), 'CODE 93'),
barcode(Barcode.code128(), 'Barcode 128'),
barcode(Barcode.ean13(), '590123412345'),
barcode(Barcode.ean8(), '9638507'),
barcode(Barcode.isbn(), '978316148410'),
barcode(Barcode.upcA(), '98765432109'),
barcode(Barcode.upcE(), '06510000432'),
],
),
);
});
... ...