|
@@ -76,45 +76,59 @@ class RegistrationController extends GetxController {
|
|
|
var labels = await registrationManager.getExamLabelsByExamNoAsync(
|
|
|
physicalExamNumber: rowData.physicalExamNumber!);
|
|
|
barCodeList.clear();
|
|
|
- for (var element in labels.eaxmLabels!) {
|
|
|
- var barCodeData = await drawRedRect(element, rowData);
|
|
|
- if (barCodeData.isNotEmpty) {
|
|
|
- barCodeList.add(barCodeData);
|
|
|
+ for (var i = 0; i < labels.eaxmLabels!.length; i++) {
|
|
|
+ final element = labels.eaxmLabels![i];
|
|
|
+ var barCode = Uint8List(0);
|
|
|
+ // if (i == 0) {
|
|
|
+ // } else {
|
|
|
+ // }
|
|
|
+ barCode = await drawBarcode(element, rowData);
|
|
|
+ if (barCode.isNotEmpty) {
|
|
|
+ if (i == 0) {
|
|
|
+ var qrCode = await drawQRcode(element, rowData);
|
|
|
+ barCodeList.add(qrCode);
|
|
|
+ }
|
|
|
+ barCodeList.add(barCode);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Future<Uint8List> drawRedRect(
|
|
|
+ Future<Uint8List> drawBarcode(
|
|
|
HealthExamLabelDTO labelDto, ResidentModel resident) async {
|
|
|
const size = Size(360, 240);
|
|
|
final svg = Barcode.code128().toSvg(
|
|
|
labelDto.uniquedCode!,
|
|
|
width: 350,
|
|
|
- height: 100,
|
|
|
+ height: 120,
|
|
|
);
|
|
|
- final qrcode = Barcode.qrCode(
|
|
|
+ final PictureInfo pictureInfo =
|
|
|
+ await vg.loadPicture(SvgStringLoader(svg), null);
|
|
|
+ var a = await _capturePainterToImage(
|
|
|
+ InfoPainter(labelDto, resident), BarcodePainter(pictureInfo), size);
|
|
|
+ return a!;
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<Uint8List> drawQRcode(
|
|
|
+ HealthExamLabelDTO labelDto, ResidentModel resident) async {
|
|
|
+ const size = Size(360, 240);
|
|
|
+ final svg = Barcode.qrCode(
|
|
|
typeNumber: 1,
|
|
|
errorCorrectLevel: BarcodeQRCorrectionLevel.low,
|
|
|
).toSvg(
|
|
|
labelDto.uniquedCode!,
|
|
|
- width: 120,
|
|
|
- height: 120,
|
|
|
+ width: 200,
|
|
|
+ height: 200,
|
|
|
);
|
|
|
- final PictureInfo qrcodeInfo =
|
|
|
- await vg.loadPicture(SvgStringLoader(qrcode), null);
|
|
|
final PictureInfo pictureInfo =
|
|
|
await vg.loadPicture(SvgStringLoader(svg), null);
|
|
|
- var a = await _capturePainterToImage(InfoPainter(labelDto, resident),
|
|
|
- BarcodePainter(pictureInfo), QrcodePainter(qrcodeInfo), size);
|
|
|
+ var a = await _capturePainterToImage(
|
|
|
+ QRInfoPainter(labelDto, resident), QrcodePainter(pictureInfo), size);
|
|
|
return a!;
|
|
|
}
|
|
|
|
|
|
/// 将CustomPainter绘制的内容转换为图片
|
|
|
Future<Uint8List?> _capturePainterToImage(
|
|
|
- CustomPainter painter,
|
|
|
- CustomPainter barcodePainter,
|
|
|
- CustomPainter qrcodePainter,
|
|
|
- Size size) async {
|
|
|
+ CustomPainter painter, CustomPainter codePainter, Size size) async {
|
|
|
final bounds = Offset.zero & size;
|
|
|
// final bounds2 = Offset.zero & Size(size.width - 20, size.height - 20);
|
|
|
final picture = PictureRecorder();
|
|
@@ -123,9 +137,7 @@ class RegistrationController extends GetxController {
|
|
|
pictureCanvas.clipRect(bounds);
|
|
|
painter.paint(pictureCanvas, size);
|
|
|
// 在Canvas上进行绘制
|
|
|
- barcodePainter.paint(pictureCanvas, size);
|
|
|
-
|
|
|
- qrcodePainter.paint(pictureCanvas, size);
|
|
|
+ codePainter.paint(pictureCanvas, size);
|
|
|
|
|
|
// 结束绘制
|
|
|
final recordedPicture = picture.endRecording();
|
|
@@ -164,7 +176,7 @@ class InfoPainter extends CustomPainter {
|
|
|
canvas.drawRect(
|
|
|
Rect.fromLTWH(0, 0, size.width, size.height), backgroundPaint);
|
|
|
canvas.drawLine(
|
|
|
- Offset(0, 125), Offset(360, 125), Paint()..color = Colors.black);
|
|
|
+ Offset(0, 95), Offset(360, 95), Paint()..color = Colors.black);
|
|
|
|
|
|
// Simulate drawing the content
|
|
|
TextSpan titleSpan = TextSpan(
|
|
@@ -189,7 +201,7 @@ class InfoPainter extends CustomPainter {
|
|
|
textDirection: TextDirection.ltr,
|
|
|
);
|
|
|
subTitleTp1.layout();
|
|
|
- subTitleTp1.paint(canvas, Offset(10, 70));
|
|
|
+ subTitleTp1.paint(canvas, Offset(10, 65));
|
|
|
|
|
|
TextSpan subTitleSpanAge = TextSpan(
|
|
|
text: '${resident.age} 岁',
|
|
@@ -201,7 +213,7 @@ class InfoPainter extends CustomPainter {
|
|
|
textDirection: TextDirection.ltr,
|
|
|
);
|
|
|
subTitleTpAge.layout();
|
|
|
- subTitleTpAge.paint(canvas, Offset(150, 70));
|
|
|
+ subTitleTpAge.paint(canvas, Offset(150, 65));
|
|
|
canvas.restore();
|
|
|
}
|
|
|
|
|
@@ -217,7 +229,7 @@ class BarcodePainter extends CustomPainter {
|
|
|
@override
|
|
|
void paint(Canvas canvas, Size size) {
|
|
|
canvas.save();
|
|
|
- canvas.translate(5, 130);
|
|
|
+ canvas.translate(5, 100);
|
|
|
canvas.scale(1, 1);
|
|
|
canvas.drawPicture(pictureInfo.picture);
|
|
|
canvas.restore(); // 恢复之前保存的绘制状态
|
|
@@ -229,13 +241,71 @@ class BarcodePainter extends CustomPainter {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+class QRInfoPainter extends CustomPainter {
|
|
|
+ HealthExamLabelDTO labelDto;
|
|
|
+ ResidentModel resident;
|
|
|
+ QRInfoPainter(this.labelDto, this.resident);
|
|
|
+ @override
|
|
|
+ void paint(Canvas canvas, Size size) {
|
|
|
+ canvas.save();
|
|
|
+ Paint backgroundPaint = Paint()..color = Colors.white;
|
|
|
+ canvas.drawRect(
|
|
|
+ Rect.fromLTWH(0, 0, size.width, size.height), backgroundPaint);
|
|
|
+ // canvas.drawLine(
|
|
|
+ // Offset(0, 95), Offset(360, 95), Paint()..color = Colors.black);
|
|
|
+
|
|
|
+ // Simulate drawing the content
|
|
|
+ TextSpan titleSpan = TextSpan(
|
|
|
+ text: '${labelDto.title ?? ''}',
|
|
|
+ style: TextStyle(fontSize: 40, height: 1, color: Colors.black),
|
|
|
+ );
|
|
|
+ TextPainter titleTp = TextPainter(
|
|
|
+ text: titleSpan,
|
|
|
+ textAlign: TextAlign.left,
|
|
|
+ textDirection: TextDirection.ltr,
|
|
|
+ );
|
|
|
+ titleTp.layout();
|
|
|
+ titleTp.paint(canvas, Offset(10, 8));
|
|
|
+
|
|
|
+ TextSpan subTitleSpanName = TextSpan(
|
|
|
+ text: '${resident.name} ',
|
|
|
+ style: TextStyle(fontSize: 30, height: 1, color: Colors.black),
|
|
|
+ );
|
|
|
+ TextPainter subTitleTp1 = TextPainter(
|
|
|
+ text: subTitleSpanName,
|
|
|
+ textAlign: TextAlign.left,
|
|
|
+ textDirection: TextDirection.ltr,
|
|
|
+ );
|
|
|
+ subTitleTp1.layout();
|
|
|
+ subTitleTp1.paint(canvas, Offset(10, 70));
|
|
|
+
|
|
|
+ TextSpan subTitleSpanAge = TextSpan(
|
|
|
+ text: '${resident.age} 岁',
|
|
|
+ style: TextStyle(fontSize: 30, height: 1, color: Colors.black),
|
|
|
+ );
|
|
|
+ TextPainter subTitleTpAge = TextPainter(
|
|
|
+ text: subTitleSpanAge,
|
|
|
+ textAlign: TextAlign.left,
|
|
|
+ textDirection: TextDirection.ltr,
|
|
|
+ );
|
|
|
+ subTitleTpAge.layout();
|
|
|
+ subTitleTpAge.paint(canvas, Offset(10, 110));
|
|
|
+ canvas.restore();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ bool shouldRepaint(covariant CustomPainter oldDelegate) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
class QrcodePainter extends CustomPainter {
|
|
|
PictureInfo pictureInfo;
|
|
|
QrcodePainter(this.pictureInfo);
|
|
|
@override
|
|
|
void paint(Canvas canvas, Size size) {
|
|
|
canvas.save();
|
|
|
- canvas.translate(230, 0);
|
|
|
+ canvas.translate(150, 0);
|
|
|
canvas.scale(1, 1);
|
|
|
canvas.drawPicture(pictureInfo.picture);
|
|
|
canvas.restore(); // 恢复之前保存的绘制状态
|