|
|
|
@ -3,12 +3,9 @@ import 'dart:convert';
|
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
|
|
import 'package:barcode_widget/barcode_widget.dart';
|
|
|
|
|
import 'package:dj_printer/src/status_enum.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
|
|
|
|
import 'package:widget_to_image/widget_to_image.dart';
|
|
|
|
|
|
|
|
|
|
class DjPrinter {
|
|
|
|
|
static late final DjPrinter _instance = DjPrinter._();
|
|
|
|
@ -175,109 +172,109 @@ class DjPrinter {
|
|
|
|
|
required int offset,
|
|
|
|
|
required bool hasPlan}) async {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteData bDCode = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
|
child: Material(
|
|
|
|
|
child:_getCode(code),
|
|
|
|
|
),
|
|
|
|
|
),pixelRatio: window.devicePixelRatio,size: const Size(25,240));
|
|
|
|
|
|
|
|
|
|
Uint8List uint8ListCode = await testComporessList(bDCode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteData bDChannel = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
|
child: Material(
|
|
|
|
|
child:_getChannel(channel)
|
|
|
|
|
),
|
|
|
|
|
),pixelRatio: window.devicePixelRatio,size: const Size(40,140));
|
|
|
|
|
|
|
|
|
|
Uint8List uint8ListChannel = await testComporessList(bDChannel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteData bDNum = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
|
child: Material(
|
|
|
|
|
child:_getNum(num)
|
|
|
|
|
),
|
|
|
|
|
),pixelRatio: window.devicePixelRatio,size: Size(20,(20*num.length).toDouble()));
|
|
|
|
|
|
|
|
|
|
Uint8List uint8ListNum = await testComporessList(bDNum);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteData bDSum = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
|
child: Material(
|
|
|
|
|
child:_getNum(sum)
|
|
|
|
|
),
|
|
|
|
|
),pixelRatio: window.devicePixelRatio,size: Size(20,(20*sum.length).toDouble()));
|
|
|
|
|
|
|
|
|
|
Uint8List uint8ListSum= await testComporessList(bDSum);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Uint8List uint8ListCountry;
|
|
|
|
|
if(hasPlan){
|
|
|
|
|
ByteData bDCountry = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
|
child: Material(
|
|
|
|
|
child:_getCountry(country)
|
|
|
|
|
),
|
|
|
|
|
),pixelRatio: window.devicePixelRatio,size: Size(country.length>4?44: 22,70));
|
|
|
|
|
|
|
|
|
|
uint8ListCountry = await testComporessList(bDCountry);
|
|
|
|
|
}else{
|
|
|
|
|
ByteData bDCountry = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
|
child: Material(
|
|
|
|
|
child:_getNoplan()
|
|
|
|
|
),
|
|
|
|
|
),pixelRatio: window.devicePixelRatio,size: const Size(22,100));
|
|
|
|
|
|
|
|
|
|
uint8ListCountry = await testComporessList(bDCountry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteData bDBarCode = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
|
child: Material(
|
|
|
|
|
child:_getBarCode(code)
|
|
|
|
|
),
|
|
|
|
|
),pixelRatio: window.devicePixelRatio,size: const Size(60,120));
|
|
|
|
|
|
|
|
|
|
Uint8List uint8ListBarCode = await testComporessList(bDBarCode);
|
|
|
|
|
|
|
|
|
|
final res = await _channel.invokeMethod('print', {
|
|
|
|
|
'code': code,
|
|
|
|
|
'channel': channel,
|
|
|
|
|
'country': country,
|
|
|
|
|
'countStr': countStr,
|
|
|
|
|
'offset': offset,
|
|
|
|
|
'hasPlan': hasPlan,
|
|
|
|
|
'byteCode': uint8ListCode,
|
|
|
|
|
'bytesChannel':uint8ListChannel,
|
|
|
|
|
'bytesCountry':uint8ListCountry,
|
|
|
|
|
'bytesBarCode':uint8ListBarCode,
|
|
|
|
|
'bytesSum':uint8ListSum,
|
|
|
|
|
'bytesNum':uint8ListNum,
|
|
|
|
|
});
|
|
|
|
|
return res;
|
|
|
|
|
//
|
|
|
|
|
// ByteData bDCode = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
// textDirection: TextDirection.ltr,
|
|
|
|
|
// child: Material(
|
|
|
|
|
// child:_getCode(code),
|
|
|
|
|
// ),
|
|
|
|
|
// ),pixelRatio: window.devicePixelRatio,size: const Size(25,240));
|
|
|
|
|
//
|
|
|
|
|
// Uint8List uint8ListCode = await testComporessList(bDCode);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// ByteData bDChannel = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
// textDirection: TextDirection.ltr,
|
|
|
|
|
// child: Material(
|
|
|
|
|
// child:_getChannel(channel)
|
|
|
|
|
// ),
|
|
|
|
|
// ),pixelRatio: window.devicePixelRatio,size: const Size(40,140));
|
|
|
|
|
//
|
|
|
|
|
// Uint8List uint8ListChannel = await testComporessList(bDChannel);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// ByteData bDNum = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
// textDirection: TextDirection.ltr,
|
|
|
|
|
// child: Material(
|
|
|
|
|
// child:_getNum(num)
|
|
|
|
|
// ),
|
|
|
|
|
// ),pixelRatio: window.devicePixelRatio,size: Size(20,(20*num.length).toDouble()));
|
|
|
|
|
//
|
|
|
|
|
// Uint8List uint8ListNum = await testComporessList(bDNum);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// ByteData bDSum = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
// textDirection: TextDirection.ltr,
|
|
|
|
|
// child: Material(
|
|
|
|
|
// child:_getNum(sum)
|
|
|
|
|
// ),
|
|
|
|
|
// ),pixelRatio: window.devicePixelRatio,size: Size(20,(20*sum.length).toDouble()));
|
|
|
|
|
//
|
|
|
|
|
// Uint8List uint8ListSum= await testComporessList(bDSum);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Uint8List uint8ListCountry;
|
|
|
|
|
// if(hasPlan){
|
|
|
|
|
// ByteData bDCountry = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
// textDirection: TextDirection.ltr,
|
|
|
|
|
// child: Material(
|
|
|
|
|
// child:_getCountry(country)
|
|
|
|
|
// ),
|
|
|
|
|
// ),pixelRatio: window.devicePixelRatio,size: Size(country.length>4?44: 22,70));
|
|
|
|
|
//
|
|
|
|
|
// uint8ListCountry = await testComporessList(bDCountry);
|
|
|
|
|
// }else{
|
|
|
|
|
// ByteData bDCountry = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
// textDirection: TextDirection.ltr,
|
|
|
|
|
// child: Material(
|
|
|
|
|
// child:_getNoplan()
|
|
|
|
|
// ),
|
|
|
|
|
// ),pixelRatio: window.devicePixelRatio,size: const Size(22,100));
|
|
|
|
|
//
|
|
|
|
|
// uint8ListCountry = await testComporessList(bDCountry);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// ByteData bDBarCode = await WidgetToImage.widgetToImage( Directionality(
|
|
|
|
|
// textDirection: TextDirection.ltr,
|
|
|
|
|
// child: Material(
|
|
|
|
|
// child:_getBarCode(code)
|
|
|
|
|
// ),
|
|
|
|
|
// ),pixelRatio: window.devicePixelRatio,size: const Size(60,120));
|
|
|
|
|
|
|
|
|
|
// Uint8List uint8ListBarCode = await testComporessList(bDBarCode);
|
|
|
|
|
|
|
|
|
|
// final res = await _channel.invokeMethod('print', {
|
|
|
|
|
// 'code': code,
|
|
|
|
|
// 'channel': channel,
|
|
|
|
|
// 'country': country,
|
|
|
|
|
// 'countStr': countStr,
|
|
|
|
|
// 'offset': offset,
|
|
|
|
|
// 'hasPlan': hasPlan,
|
|
|
|
|
// 'byteCode': uint8ListCode,
|
|
|
|
|
// 'bytesChannel':uint8ListChannel,
|
|
|
|
|
// 'bytesCountry':uint8ListCountry,
|
|
|
|
|
// 'bytesBarCode':uint8ListBarCode,
|
|
|
|
|
// 'bytesSum':uint8ListSum,
|
|
|
|
|
// 'bytesNum':uint8ListNum,
|
|
|
|
|
// });
|
|
|
|
|
// return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<Uint8List> testComporessList(ByteData data) async {
|
|
|
|
|
// Future<Uint8List> testComporessList(ByteData data) async {
|
|
|
|
|
|
|
|
|
|
final buffer = data.buffer;
|
|
|
|
|
|
|
|
|
|
var result = await FlutterImageCompress.compressWithList(
|
|
|
|
|
buffer.asUint8List(),
|
|
|
|
|
quality: 1,
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
print(buffer.asUint8List().length);
|
|
|
|
|
print(result.length);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
// final buffer = data.buffer;
|
|
|
|
|
//
|
|
|
|
|
// var result = await FlutterImageCompress.compressWithList(
|
|
|
|
|
// buffer.asUint8List(),
|
|
|
|
|
// quality: 1,
|
|
|
|
|
//
|
|
|
|
|
// );
|
|
|
|
|
// print(buffer.asUint8List().length);
|
|
|
|
|
// print(result.length);
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Widget _getCountry(String country){
|
|
|
|
@ -361,18 +358,18 @@ class DjPrinter {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Widget _getBarCode(String code){
|
|
|
|
|
return RotatedBox(
|
|
|
|
|
quarterTurns: 1,
|
|
|
|
|
child: BarcodeWidget(
|
|
|
|
|
barcode: Barcode.code128(),
|
|
|
|
|
data: code,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 10
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
// Widget _getBarCode(String code){
|
|
|
|
|
// return RotatedBox(
|
|
|
|
|
// quarterTurns: 1,
|
|
|
|
|
// child: BarcodeWidget(
|
|
|
|
|
// barcode: Barcode.code128(),
|
|
|
|
|
// data: code,
|
|
|
|
|
// style: TextStyle(
|
|
|
|
|
// fontSize: 10
|
|
|
|
|
// ),
|
|
|
|
|
// ),
|
|
|
|
|
// );
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Widget _getCard(String code, String channel, String country, String countStr,
|
|
|
|
|
int offset, bool hasPlan) {
|
|
|
|
|