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