David PHAM-VAN

Bump barcode dependency to 2.2.3

@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 ## 3.8.3 3 ## 3.8.3
4 4
5 - Fix Arabic TextAlign.justify issues Set default text align based on text direction [Milad akarie] 5 - Fix Arabic TextAlign.justify issues Set default text align based on text direction [Milad akarie]
  6 +- Bump barcode dependency to 2.2.3
  7 +
6 ## 3.8.2 8 ## 3.8.2
7 9
8 - Fix Compressed Cross-Reference ID 10 - Fix Compressed Cross-Reference ID
@@ -30,17 +30,19 @@ import 'theme.dart'; @@ -30,17 +30,19 @@ import 'theme.dart';
30 import 'widget.dart'; 30 import 'widget.dart';
31 31
32 class _BarcodeWidget extends Widget { 32 class _BarcodeWidget extends Widget {
33 - _BarcodeWidget({  
34 - required this.data, 33 + _BarcodeWidget(
  34 + this.dataBytes,
  35 + this.dataString,
35 this.barcode, 36 this.barcode,
36 - this.color = PdfColors.black, 37 + this.color,
37 this.drawText, 38 this.drawText,
38 this.textStyle, 39 this.textStyle,
39 this.textPadding, 40 this.textPadding,
40 - }); 41 + );
41 42
42 /// the barcode data 43 /// the barcode data
43 - final Uint8List data; 44 + final String? dataString;
  45 + final Uint8List? dataBytes;
44 46
45 final Barcode? barcode; 47 final Barcode? barcode;
46 48
@@ -58,20 +60,31 @@ class _BarcodeWidget extends Widget { @@ -58,20 +60,31 @@ class _BarcodeWidget extends Widget {
58 box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest); 60 box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest);
59 } 61 }
60 62
  63 + Iterable<BarcodeElement> get barcodeDraw => dataBytes != null
  64 + ? barcode!.makeBytes(
  65 + dataBytes!,
  66 + width: box!.width,
  67 + height: box!.height,
  68 + drawText: drawText!,
  69 + fontHeight: textStyle!.fontSize!,
  70 + textPadding: textPadding!,
  71 + )
  72 + : barcode!.make(
  73 + dataString!,
  74 + width: box!.width,
  75 + height: box!.height,
  76 + drawText: drawText!,
  77 + fontHeight: textStyle!.fontSize!,
  78 + textPadding: textPadding!,
  79 + );
  80 +
61 @override 81 @override
62 void paint(Context context) { 82 void paint(Context context) {
63 super.paint(context); 83 super.paint(context);
64 84
65 final textList = <BarcodeText>[]; 85 final textList = <BarcodeText>[];
66 86
67 - for (final element in barcode!.makeBytes(  
68 - data,  
69 - width: box!.width,  
70 - height: box!.height,  
71 - drawText: drawText!,  
72 - fontHeight: textStyle!.fontSize!,  
73 - textPadding: textPadding!,  
74 - )) { 87 + for (final element in barcodeDraw) {
75 if (element is BarcodeBar) { 88 if (element is BarcodeBar) {
76 if (element.black) { 89 if (element.black) {
77 context.canvas.drawRect( 90 context.canvas.drawRect(
@@ -136,14 +149,7 @@ class _BarcodeWidget extends Widget { @@ -136,14 +149,7 @@ class _BarcodeWidget extends Widget {
136 super.debugPaint(context); 149 super.debugPaint(context);
137 150
138 if (drawText!) { 151 if (drawText!) {
139 - for (final element in barcode!.makeBytes(  
140 - data,  
141 - width: box!.width,  
142 - height: box!.height,  
143 - drawText: drawText!,  
144 - fontHeight: textStyle!.fontSize!,  
145 - textPadding: textPadding!,  
146 - )) { 152 + for (final element in barcodeDraw) {
147 if (element is BarcodeText) { 153 if (element is BarcodeText) {
148 context.canvas.drawRect( 154 context.canvas.drawRect(
149 box!.x + element.left, 155 box!.x + element.left,
@@ -165,38 +171,25 @@ class _BarcodeWidget extends Widget { @@ -165,38 +171,25 @@ class _BarcodeWidget extends Widget {
165 /// Draw a barcode using String data 171 /// Draw a barcode using String data
166 class BarcodeWidget extends StatelessWidget { 172 class BarcodeWidget extends StatelessWidget {
167 /// Create a BarcodeWidget 173 /// Create a BarcodeWidget
168 - factory BarcodeWidget({ 174 + BarcodeWidget({
169 required String data, 175 required String data,
170 - required Barcode barcode,  
171 - PdfColor color = PdfColors.black,  
172 - PdfColor? backgroundColor,  
173 - BoxDecoration? decoration,  
174 - EdgeInsets? margin,  
175 - EdgeInsets? padding,  
176 - double? width,  
177 - double? height,  
178 - bool drawText = true,  
179 - TextStyle? textStyle,  
180 - double textPadding = 0,  
181 - }) =>  
182 - BarcodeWidget.fromBytes(  
183 - data: utf8.encoder.convert(data),  
184 - barcode: barcode,  
185 - color: color,  
186 - backgroundColor: backgroundColor,  
187 - decoration: decoration,  
188 - margin: margin,  
189 - padding: padding,  
190 - width: width,  
191 - height: height,  
192 - drawText: drawText,  
193 - textStyle: textStyle,  
194 - textPadding: textPadding,  
195 - ); 176 + required this.barcode,
  177 + this.color = PdfColors.black,
  178 + this.backgroundColor,
  179 + this.decoration,
  180 + this.margin,
  181 + this.padding,
  182 + this.width,
  183 + this.height,
  184 + this.drawText = true,
  185 + this.textStyle,
  186 + this.textPadding = 0,
  187 + }) : dataBytes = null,
  188 + dataString = data;
196 189
197 /// Draw a barcode using Uint8List data 190 /// Draw a barcode using Uint8List data
198 BarcodeWidget.fromBytes({ 191 BarcodeWidget.fromBytes({
199 - required this.data, 192 + required Uint8List data,
200 required this.barcode, 193 required this.barcode,
201 this.color = PdfColors.black, 194 this.color = PdfColors.black,
202 this.backgroundColor, 195 this.backgroundColor,
@@ -208,10 +201,14 @@ class BarcodeWidget extends StatelessWidget { @@ -208,10 +201,14 @@ class BarcodeWidget extends StatelessWidget {
208 this.drawText = true, 201 this.drawText = true,
209 this.textStyle, 202 this.textStyle,
210 this.textPadding = 0, 203 this.textPadding = 0,
211 - }); 204 + }) : dataBytes = data,
  205 + dataString = null;
212 206
213 /// the barcode data 207 /// the barcode data
214 - final Uint8List data; 208 + final String? dataString;
  209 + final Uint8List? dataBytes;
  210 + Uint8List get data =>
  211 + dataBytes ?? Uint8List.fromList(utf8.encode(dataString!));
215 212
216 /// The type of barcode to use. 213 /// The type of barcode to use.
217 /// use: 214 /// use:
@@ -254,7 +251,7 @@ class BarcodeWidget extends StatelessWidget { @@ -254,7 +251,7 @@ class BarcodeWidget extends StatelessWidget {
254 251
255 @override 252 @override
256 Widget build(Context context) { 253 Widget build(Context context) {
257 - final defaultstyle = Theme.of(context).defaultTextStyle.copyWith( 254 + final defaultStyle = Theme.of(context).defaultTextStyle.copyWith(
258 font: Font.courier(), 255 font: Font.courier(),
259 fontNormal: Font.courier(), 256 fontNormal: Font.courier(),
260 fontBold: Font.courierBold(), 257 fontBold: Font.courierBold(),
@@ -263,15 +260,16 @@ class BarcodeWidget extends StatelessWidget { @@ -263,15 +260,16 @@ class BarcodeWidget extends StatelessWidget {
263 lineSpacing: 1, 260 lineSpacing: 1,
264 fontSize: height != null ? height! * 0.2 : null, 261 fontSize: height != null ? height! * 0.2 : null,
265 ); 262 );
266 - final _textStyle = defaultstyle.merge(textStyle); 263 + final _textStyle = defaultStyle.merge(textStyle);
267 264
268 Widget child = _BarcodeWidget( 265 Widget child = _BarcodeWidget(
269 - data: data,  
270 - color: color,  
271 - barcode: barcode,  
272 - drawText: drawText,  
273 - textStyle: _textStyle,  
274 - textPadding: textPadding, 266 + dataBytes,
  267 + dataString,
  268 + barcode,
  269 + color,
  270 + drawText,
  271 + _textStyle,
  272 + textPadding,
275 ); 273 );
276 274
277 if (padding != null) { 275 if (padding != null) {
@@ -10,7 +10,7 @@ environment: @@ -10,7 +10,7 @@ environment:
10 10
11 dependencies: 11 dependencies:
12 archive: ^3.1.0 12 archive: ^3.1.0
13 - barcode: ">=2.2.0 <3.0.0" 13 + barcode: ">=2.2.3 <3.0.0"
14 crypto: ^3.0.0 14 crypto: ^3.0.0
15 image: ">=3.0.1 <4.0.0" 15 image: ">=3.0.1 <4.0.0"
16 meta: ">=1.3.0 <2.0.0" 16 meta: ">=1.3.0 <2.0.0"