Showing
5 changed files
with
62 additions
and
38 deletions
| @@ -136,7 +136,9 @@ class _BarcodeWidget extends Widget { | @@ -136,7 +136,9 @@ class _BarcodeWidget extends Widget { | ||
| 136 | class BarcodeWidget extends StatelessWidget { | 136 | class BarcodeWidget extends StatelessWidget { |
| 137 | BarcodeWidget({ | 137 | BarcodeWidget({ |
| 138 | @required this.data, | 138 | @required this.data, |
| 139 | - this.type = BarcodeType.Code39, | 139 | + @Deprecated('Use `Barcode.fromType(type)` instead') |
| 140 | + BarcodeType type = BarcodeType.Code39, | ||
| 141 | + Barcode barcode, | ||
| 140 | this.color = PdfColors.black, | 142 | this.color = PdfColors.black, |
| 141 | this.backgroundColor, | 143 | this.backgroundColor, |
| 142 | this.decoration, | 144 | this.decoration, |
| @@ -146,12 +148,14 @@ class BarcodeWidget extends StatelessWidget { | @@ -146,12 +148,14 @@ class BarcodeWidget extends StatelessWidget { | ||
| 146 | this.height, | 148 | this.height, |
| 147 | this.drawText = true, | 149 | this.drawText = true, |
| 148 | this.textStyle, | 150 | this.textStyle, |
| 149 | - }); | 151 | + }) : |
| 152 | + // ignore: deprecated_member_use_from_same_package | ||
| 153 | + barcode = barcode ?? Barcode.fromType(type); | ||
| 150 | 154 | ||
| 151 | /// the barcode data | 155 | /// the barcode data |
| 152 | final String data; | 156 | final String data; |
| 153 | 157 | ||
| 154 | - final BarcodeType type; | 158 | + final Barcode barcode; |
| 155 | 159 | ||
| 156 | final PdfColor color; | 160 | final PdfColor color; |
| 157 | 161 | ||
| @@ -183,38 +187,38 @@ class BarcodeWidget extends StatelessWidget { | @@ -183,38 +187,38 @@ class BarcodeWidget extends StatelessWidget { | ||
| 183 | ); | 187 | ); |
| 184 | final TextStyle _textStyle = defaultstyle.merge(textStyle); | 188 | final TextStyle _textStyle = defaultstyle.merge(textStyle); |
| 185 | 189 | ||
| 186 | - Widget barcode = _BarcodeWidget( | 190 | + Widget child = _BarcodeWidget( |
| 187 | data: data, | 191 | data: data, |
| 188 | color: color, | 192 | color: color, |
| 189 | - barcode: Barcode.fromType(type), | 193 | + barcode: barcode, |
| 190 | drawText: drawText, | 194 | drawText: drawText, |
| 191 | textStyle: _textStyle, | 195 | textStyle: _textStyle, |
| 192 | ); | 196 | ); |
| 193 | 197 | ||
| 194 | if (padding != null) { | 198 | if (padding != null) { |
| 195 | - barcode = Padding(padding: padding, child: barcode); | 199 | + child = Padding(padding: padding, child: child); |
| 196 | } | 200 | } |
| 197 | 201 | ||
| 198 | if (decoration != null) { | 202 | if (decoration != null) { |
| 199 | - barcode = DecoratedBox( | 203 | + child = DecoratedBox( |
| 200 | decoration: decoration, | 204 | decoration: decoration, |
| 201 | - child: barcode, | 205 | + child: child, |
| 202 | ); | 206 | ); |
| 203 | } else if (backgroundColor != null) { | 207 | } else if (backgroundColor != null) { |
| 204 | - barcode = DecoratedBox( | 208 | + child = DecoratedBox( |
| 205 | decoration: BoxDecoration(color: backgroundColor), | 209 | decoration: BoxDecoration(color: backgroundColor), |
| 206 | - child: barcode, | 210 | + child: child, |
| 207 | ); | 211 | ); |
| 208 | } | 212 | } |
| 209 | 213 | ||
| 210 | if (width != null || height != null) { | 214 | if (width != null || height != null) { |
| 211 | - barcode = SizedBox(width: width, height: height, child: barcode); | 215 | + child = SizedBox(width: width, height: height, child: child); |
| 212 | } | 216 | } |
| 213 | 217 | ||
| 214 | if (margin != null) { | 218 | if (margin != null) { |
| 215 | - barcode = Padding(padding: margin, child: barcode); | 219 | + child = Padding(padding: margin, child: child); |
| 216 | } | 220 | } |
| 217 | 221 | ||
| 218 | - return barcode; | 222 | + return child; |
| 219 | } | 223 | } |
| 220 | } | 224 | } |
| @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | ||
| 4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf | 4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf |
| 5 | repository: https://github.com/DavBfr/dart_pdf | 5 | repository: https://github.com/DavBfr/dart_pdf |
| 6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues | 6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues |
| 7 | -version: 1.3.29 | 7 | +version: 1.3.30 |
| 8 | 8 | ||
| 9 | environment: | 9 | environment: |
| 10 | sdk: ">=2.3.0 <3.0.0" | 10 | sdk: ">=2.3.0 <3.0.0" |
| @@ -25,30 +25,25 @@ import 'package:test/test.dart'; | @@ -25,30 +25,25 @@ import 'package:test/test.dart'; | ||
| 25 | 25 | ||
| 26 | Document pdf; | 26 | Document pdf; |
| 27 | 27 | ||
| 28 | -void main() { | ||
| 29 | - setUpAll(() { | ||
| 30 | - Document.debug = true; | ||
| 31 | - pdf = Document(); | ||
| 32 | - }); | ||
| 33 | - | ||
| 34 | - test('Barcode Widgets', () { | ||
| 35 | - pdf.addPage( | ||
| 36 | - MultiPage( | ||
| 37 | - build: (Context context) => List<Widget>.generate( | ||
| 38 | - BarcodeType.values.length, | ||
| 39 | - (int index) { | 28 | +Widget barcode(Barcode barcode, String data) { |
| 40 | return Row( | 29 | return Row( |
| 41 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, | 30 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
| 42 | children: <Widget>[ | 31 | children: <Widget>[ |
| 43 | - Text(BarcodeType.values[index].toString()), | ||
| 44 | - BarcodeWidget( | ||
| 45 | - type: BarcodeType.values[index], | ||
| 46 | - data: 'HELLO 123', | 32 | + Flexible( |
| 33 | + fit: FlexFit.tight, | ||
| 34 | + child: Center( | ||
| 35 | + child: Text(barcode.name), | ||
| 36 | + ), | ||
| 37 | + ), | ||
| 38 | + Flexible( | ||
| 39 | + fit: FlexFit.tight, | ||
| 40 | + child: BarcodeWidget( | ||
| 41 | + barcode: barcode, | ||
| 42 | + data: data, | ||
| 47 | width: 200, | 43 | width: 200, |
| 48 | - height: 50, | 44 | + height: 80, |
| 49 | margin: const EdgeInsets.symmetric(vertical: 20), | 45 | margin: const EdgeInsets.symmetric(vertical: 20), |
| 50 | - padding: | ||
| 51 | - const EdgeInsets.symmetric(horizontal: 10, vertical: 3), | 46 | + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 3), |
| 52 | decoration: BoxDecoration( | 47 | decoration: BoxDecoration( |
| 53 | border: BoxBorder( | 48 | border: BoxBorder( |
| 54 | color: PdfColors.blue, | 49 | color: PdfColors.blue, |
| @@ -56,12 +51,33 @@ void main() { | @@ -56,12 +51,33 @@ void main() { | ||
| 56 | bottom: true, | 51 | bottom: true, |
| 57 | left: true, | 52 | left: true, |
| 58 | right: true, | 53 | right: true, |
| 59 | - )), | 54 | + ), |
| 55 | + ), | ||
| 56 | + ), | ||
| 60 | ), | 57 | ), |
| 61 | ], | 58 | ], |
| 62 | ); | 59 | ); |
| 63 | - }, | ||
| 64 | - ), | 60 | +} |
| 61 | + | ||
| 62 | +void main() { | ||
| 63 | + setUpAll(() { | ||
| 64 | + Document.debug = true; | ||
| 65 | + pdf = Document(); | ||
| 66 | + }); | ||
| 67 | + | ||
| 68 | + test('Barcode Widgets', () { | ||
| 69 | + pdf.addPage( | ||
| 70 | + MultiPage( | ||
| 71 | + build: (Context context) => <Widget>[ | ||
| 72 | + barcode(Barcode.code39(), 'CODE 39'), | ||
| 73 | + barcode(Barcode.code93(), 'CODE 93'), | ||
| 74 | + barcode(Barcode.code128(), 'Barcode 128'), | ||
| 75 | + barcode(Barcode.ean13(), '590123412345'), | ||
| 76 | + barcode(Barcode.ean8(), '9638507'), | ||
| 77 | + barcode(Barcode.isbn(), '978316148410'), | ||
| 78 | + barcode(Barcode.upcA(), '98765432109'), | ||
| 79 | + barcode(Barcode.upcE(), '06510000432'), | ||
| 80 | + ], | ||
| 65 | ), | 81 | ), |
| 66 | ); | 82 | ); |
| 67 | }); | 83 | }); |
No preview for this file type
-
Please register or login to post a comment