适配新打印纸

master
章文轩 2 years ago
parent 07c8b30d30
commit a916f14567

@ -2,6 +2,7 @@
<library name="Flutter Plugins" type="FlutterPluginsLibraryType">
<CLASSES>
<root url="file://$PROJECT_DIR$" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.flutter-io.cn/flutter_image_compress-1.1.0" />
</CLASSES>
<JAVADOC />
<SOURCES />

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

@ -1,15 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="2f8e3712-04e2-429a-bcea-c8db1a54008e" name="默认变更列表" comment="">
<change beforePath="$PROJECT_DIR$/.idea/libraries/Dart_SDK.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/libraries/Dart_SDK.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/libraries/Flutter_Plugins.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/libraries/Flutter_Plugins.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/.idea/gradle.xml" beforeDir="false" afterPath="$PROJECT_DIR$/android/.idea/gradle.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/.idea/modules.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/android/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/android/build.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/dj/printer/dj_printer/AsPrint.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/dj/printer/dj_printer/AsPrint.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/android/src/main/java/com/dj/printer/dj_printer/DjPrinterPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/dj/printer/dj_printer/DjPrinterPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dj_printer.iml" beforeDir="false" afterPath="$PROJECT_DIR$/dj_printer.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/android/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/example/android/build.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/lib/main.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/lib/main.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/example/pubspec.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/pubspec.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/example/pubspec.yaml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/dj_printer.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/dj_printer.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/pubspec.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pubspec.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/pubspec.yaml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -35,9 +43,12 @@
</file-type-list>
</component>
<component name="HighlightingSettingsPerFile">
<setting file="file://$PROJECT_DIR$/example/lib/main.dart" root0="SKIP_INSPECTION" />
<setting file="file://$PROJECT_DIR$/example/pubspec.yaml" root0="SKIP_INSPECTION" />
<setting file="file://$PROJECT_DIR$/android/src/main/java/com/dj/printer/dj_printer/DjPrinterPlugin.java" root0="SKIP_INSPECTION" />
<setting file="file://$PROJECT_DIR$/android/src/main/java/com/dj/printer/dj_printer/AsPrint.java" root0="SKIP_INSPECTION" />
<setting file="file://$PROJECT_DIR$/android/src/main/java/com/dj/printer/dj_printer/Blutooth.java" root0="SKIP_INSPECTION" />
<setting file="file://$PROJECT_DIR$/lib/dj_printer.dart" root0="SKIP_INSPECTION" />
<setting file="file://$PROJECT_DIR$/example/lib/main.dart" root0="SKIP_INSPECTION" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
@ -65,7 +76,7 @@
<property name="dart.analysis.tool.window.visible" value="false" />
<property name="io.flutter.reload.alreadyRun" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="flutter.settings" />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
<property name="show.migrate.to.gradle.popup" value="false" />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="应用程序级" UseSingleDictionary="true" transferred="true" />
@ -95,6 +106,7 @@
</entry>
</map>
</option>
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />

@ -24,6 +24,7 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 30
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8

@ -1,5 +1,7 @@
package com.dj.printer.dj_printer;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import com.sewoo.jpos.command.CPCLConst;
@ -7,6 +9,8 @@ import com.sewoo.jpos.printer.CPCLPrinter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
public class AsPrint {
@ -20,23 +24,98 @@ public class AsPrint {
cpclPrinter.setMeasure(CPCLConst.LK_CPCL_MILLI);
}
public void printAsCode(String code, String channel, String country, String countStr, int offset, boolean hasPlan) throws IOException {
printTest();
// if (hasPlan) {
// PrintPlan(code, channel, country, countStr, offset);
// } else {
// PrintNoPlan(code, countStr, offset);
// }
public void printAsCode(String code, String channel, String country, String countStr,
int offset, boolean hasPlan, byte[] bytesCode, byte[] bytesChannel,
byte[] bytesCountry ,byte[] bytesBarCode,byte[] bytesNum ,byte[] bytesSum) throws IOException {
Bitmap imgCode = BitmapFactory.decodeByteArray(bytesCode, 0, bytesCode.length);
Bitmap imgChannel = BitmapFactory.decodeByteArray(bytesChannel, 0, bytesChannel.length);
Bitmap imgCountry = BitmapFactory.decodeByteArray(bytesCountry, 0, bytesCountry.length);
Bitmap imgBarCode = BitmapFactory.decodeByteArray(bytesBarCode, 0, bytesBarCode.length);
Bitmap imgNum = BitmapFactory.decodeByteArray(bytesNum, 0, bytesNum.length);
Bitmap imgSum = BitmapFactory.decodeByteArray(bytesSum, 0, bytesSum.length);
if (hasPlan) {
printNewPlan(code, channel, country, countStr, offset, imgCode, imgChannel, imgCountry,imgBarCode,imgNum,imgSum);
} else {
printNewNoPlan(code, channel, country, countStr, offset, imgCode, imgCountry,imgBarCode,imgNum,imgSum);
}
}
private void printTest() throws UnsupportedEncodingException {
cpclPrinter.setForm(0, 203, 203, 500, 575, 0, 1);
private void printNewPlan(String code, String channel, String country, String countStr, int offset,
Bitmap imgCode, Bitmap imgChannel, Bitmap imgCountry,
Bitmap imgBarCode,Bitmap imgNum,Bitmap imgSum) throws IOException {
cpclPrinter.setForm(3, 203, 203, 800, 575, 0, 1);
cpclPrinter.setMedia(CPCLConst.LK_CPCL_LABEL);
cpclPrinter.setJustification(CPCLConst.LK_CPCL_CENTER);
cpclPrinter.printBox(5,5,500,300,3);
cpclPrinter.printLine(5,50,500,50,3);
cpclPrinter.printLine(430,300,480,250,3);
cpclPrinter.setJustification(CPCLConst.LK_CPCL_LEFT);
cpclPrinter.printBox(0, 7, 570, 800, 3);
cpclPrinter.printLine(265, 7, 265, 800, 3);
cpclPrinter.printLine(424, 7, 424, 800, 3);
cpclPrinter.printLine(0, 526, 424, 526, 3);
cpclPrinter.printLine(70, 590, 200, 730, 3);
cpclPrinter.printBitmap(imgCode, 460, 50);
cpclPrinter.printBitmap(imgChannel, 295, 60);
cpclPrinter.printBitmap(imgCountry, 320, country.length()>3?570:580);
cpclPrinter.printBitmap(imgBarCode, 40, 80);
cpclPrinter.printBitmap(imgNum, 150, 600);
cpclPrinter.printBitmap(imgSum, 70, 690);
cpclPrinter.printForm();
}
private void printNewNoPlan(String code, String channel, String country, String countStr, int offset,
Bitmap imgCode, Bitmap imgCountry,
Bitmap imgBarCode,Bitmap imgNum,Bitmap imgSum) throws IOException {
cpclPrinter.setForm(3, 203, 203, 800, 575, 0, 1);
cpclPrinter.setMedia(CPCLConst.LK_CPCL_LABEL);
cpclPrinter.setJustification(CPCLConst.LK_CPCL_LEFT);
cpclPrinter.printBox(0, 10, 570, 795, 3);
cpclPrinter.printLine(265, 10, 265, 795, 3);
cpclPrinter.printLine(424, 10, 424, 795, 3);
cpclPrinter.printLine(0, 526, 265, 526, 3);
cpclPrinter.printLine(70, 590, 200, 730, 3);
cpclPrinter.printBitmap(imgCode, 460, 50);
cpclPrinter.printBitmap(imgCountry, 320,270);
cpclPrinter.printBitmap(imgBarCode, 40, 80);
cpclPrinter.printBitmap(imgNum, 150, 600);
cpclPrinter.printBitmap(imgSum, 70, 690);
cpclPrinter.printForm();
}
@ -78,3 +157,4 @@ public class AsPrint {
return cpclPrinter.status();
}
}

@ -90,7 +90,23 @@ public class DjPrinterPlugin implements FlutterPlugin, MethodCallHandler {
String countStr = call.argument("countStr");
int offset = call.argument("offset");
boolean hasPlan = call.argument("hasPlan");
asPrint.printAsCode(code, channel, country, countStr, offset, hasPlan);
byte[] byteCode = call.argument("byteCode");
byte[] bytesChannel = call.argument("bytesChannel");
byte[] bytesCountry = call.argument("bytesCountry");
byte[] bytesBarCode =call.argument("bytesBarCode");
byte[] bytesSum = call.argument("bytesSum");
byte[] bytesNum =call.argument("bytesNum");
asPrint.printAsCode(code, channel, country, countStr, offset, hasPlan,byteCode,bytesChannel,bytesCountry,bytesBarCode,bytesNum,bytesSum);
//asPrint.printAsCode();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {

@ -12,6 +12,7 @@
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
</content>
<orderEntry type="jdk" jdkName="Android API 29 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />

@ -1,4 +1,5 @@
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
@ -6,6 +7,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:convert';
import 'package:barcode_widget/barcode_widget.dart';
import 'package:dj_printer/dj_printer.dart';
import 'package:dj_printer/src/device_model.dart';
import 'package:flutter/material.dart';
@ -73,6 +74,7 @@ class _MyAppState extends State<MyApp> {
TextButton(
onPressed: () {
devices.clear();
setState(() {});
DjPrinter().startSearch;
},
child: const Text('扫描设备')),
@ -92,13 +94,13 @@ class _MyAppState extends State<MyApp> {
),
TextButton(
onPressed: () {
DjPrinter().printAScode(
DjPrinter().printAScodeByImg(
code: 'ASSZ2022012500010002',
channel: 'cosco定提-月达-卡派',
country: '美国',
channel: '加拿大温哥华海派快线-卡派/UPS派送',
country: '加拿大',
countStr: '10/20',
offset: 0,
hasPlan: false);
hasPlan: false, sum: '20', num: '5');
},
child: const Text('打印')),
@ -109,11 +111,167 @@ class _MyAppState extends State<MyApp> {
onPressed: () {
DjPrinter().disposeConnect();
},
child: const Text('取消链接'))
child: const Text('取消链接')),
_getCard('ASSZ2022012500010002', '加拿大温哥华海派快线-卡派/UPS派送', '加拿大',
'10/20', 0, true)
],
),
),
),
);
}
_getCard(String code, String channel, String country, String countStr,
int offset, bool hasPlan) {
return Container(
margin: EdgeInsets.all(5),
width: 90,
height: 200,
color: Colors.red,
// decoration: BoxDecoration(
// border: Border.all(color: Colors.black,width: 2)
// ),
child: RotatedBox(
quarterTurns: 1,
child: BarcodeWidget(
barcode: Barcode.code128(),
data: code,
style: TextStyle(
fontSize: 10
),
),
)
//
// Row(
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Container(
// width: 197 / 3.7,
// height: 950 / 3.7,
// decoration: BoxDecoration(
// color: Colors.white,
// border: Border(
// right: BorderSide(
// color: Colors.black,
// width: 0.5,
// )),
// ),
// alignment: Alignment.center,
// child: RotatedBox(
// quarterTurns: 3,
// child: Text(
// code,
// style: TextStyle(
// color: Colors.black,
// fontSize: 20,
// fontWeight: FontWeight.bold),
// ),
// ),
// ),
// Container(
// width: 215 / 3.7,
// height: 950 / 3.7,
// decoration: BoxDecoration(
// border: Border(
// right: BorderSide(
// color: Colors.black,
// width: 0.5,
// )),
// ),
// alignment: Alignment.center,
// child: Column(
// children: [
// Container(
// width: 215 / 3.7,
// height: 950 / 3.7 / 3,
// decoration: BoxDecoration(
// border: Border(
// bottom: BorderSide(
// color: Colors.black,
// width: 0.5,
// )),
// ),
// alignment: Alignment.center,
// child: RotatedBox(
// quarterTurns: 3,
// child: Text(
// country,
// style: TextStyle(
// color: Colors.black,
// fontSize: 17,
// fontWeight: FontWeight.bold),
// ),
// ),
// ),
// Container(
// width: 215 / 3.7,
// height: 950 / 3.7 / 3 * 2 - 4,
// padding: EdgeInsets.symmetric(vertical: 10),
// alignment: Alignment.center,
// child: RotatedBox(
// quarterTurns: 3,
// child: Text(
// channel,
// style: TextStyle(
// color: Colors.black,
// fontSize: 15,
// ),
// ),
// ),
// )
// ],
// )),
// Container(
// width: 358 / 3.7 -20,
// height: 950 / 3.7,
// alignment: Alignment.center,
// child: Column(
// children: [
// Container(
// width: 358 / 3.7 -20,
// height: 950 / 3.7 / 3,
// decoration: BoxDecoration(
// border: Border(
// bottom: BorderSide(
// color: Colors.black,
// width: 0.5,
// )),
// ),
// alignment: Alignment.center,
// child: RotatedBox(
// quarterTurns: 3,
// child: Text(
// countStr,
// style: TextStyle(
// color: Colors.black,
// fontSize: 17,
// fontWeight: FontWeight.bold),
// ),
// ),
// ),
// Container(
// width: 358 / 3.7 -30,
// height: 950 / 3.7 / 3 * 2 - 1.5,
// padding: EdgeInsets.only(left: 15,top: 15,bottom: 15,right: 10) ,
// child: RotatedBox(
// quarterTurns: 3,
// child: BarcodeWidget(
//
// barcode: Barcode.code128(),
// data: code,
// style: TextStyle(
// fontSize: 10
// ),
// ),
// ),
// )
// ],
// )),
// ],
// ),
);
}
}

@ -5,56 +5,70 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.8.2"
barcode:
dependency: transitive
description:
name: barcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.1"
barcode_widget:
dependency: "direct main"
description:
name: barcode_widget
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.2"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
bot_toast:
dependency: "direct main"
description:
name: bot_toast
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.2"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.16.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.5"
dj_printer:
@ -68,7 +82,7 @@ packages:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
flutter:
@ -76,11 +90,18 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_image_compress:
dependency: transitive
description:
name: flutter_image_compress
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
flutter_test:
@ -92,79 +113,86 @@ packages:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.4"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.1"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "9.2.0"
permission_handler_android:
dependency: transitive
description:
name: permission_handler_android
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "9.0.2+1"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "9.0.4"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.7.0"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.2"
qr:
dependency: transitive
description:
name: qr
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.1"
sky_engine:
dependency: transitive
description: flutter
@ -174,51 +202,58 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.2"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.9"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.2"
widget_to_image:
dependency: "direct main"
description:
name: widget_to_image
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
sdks:
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.8.0"

@ -30,6 +30,8 @@ dependencies:
cupertino_icons: ^1.0.2
permission_handler: ^9.2.0
bot_toast: ^4.0.1
widget_to_image: ^2.0.0
barcode_widget: ^2.0.2
dev_dependencies:
flutter_test:

@ -1,7 +1,14 @@
import 'dart:async';
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._();
@ -133,4 +140,369 @@ class DjPrinter {
});
return res;
}
Future<bool?> printAScodeByImg({required String code,
required String channel,
required String country,
required String num,
required String sum,
required String countStr,
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;
}
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;
}
Widget _getCountry(String country){
return RotatedBox(
quarterTurns: 1,
child: Text(
country,
maxLines: 2,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.black,
fontSize: 17,
fontWeight: FontWeight.bold,
),
),
);
}
Widget _getNoplan(){
return RotatedBox(
quarterTurns: 1,
child: Text(
'未 建 计 划',
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.black,
fontSize: 17,
fontWeight: FontWeight.bold,
),
),
);
}
Widget _getNum(String num){
return RotatedBox(
quarterTurns: 1,
child: Text(
num,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.black,
fontSize: 17,
fontWeight: FontWeight.bold,
),
),
);
}
Widget _getChannel(String channel){
return RotatedBox(
quarterTurns: 1,
child: Text(
channel,
maxLines: 2,
style: const TextStyle(
color: Colors.black,
fontSize: 13,
),
),
);
}
Widget _getCode(String code){
return RotatedBox(
quarterTurns: 1,
child: Text(
code,
style: const TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold),
),
);
}
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) {
return RotatedBox(
quarterTurns: 3,
child: Text(
code,
style: const TextStyle(
color: Colors.black,
fontSize: 15,
),
),
);
Container(
//margin: EdgeInsets.all(5),
width: 700 / 3.7,
height: 950 / 3.7,
// decoration: BoxDecoration(
// color: Colors.white,
// border: Border.all(color: Colors.black, width: 0.5)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 197 / 3.7,
height: 950 / 3.7,
// decoration: BoxDecoration(
// color: Colors.white,
// border: Border(
// right: BorderSide(
// color: Colors.black,
// width: 0.5,
// )),
// ),
alignment: Alignment.center,
child: RotatedBox(
quarterTurns: 3,
child: Text(
code,
style: TextStyle(
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
),
Container(
width: 215 / 3.7,
height: 950 / 3.7,
// decoration: BoxDecoration(
// border: Border(
// right: BorderSide(
// color: Colors.black,
// width: 0.5,
// )),
// ),
alignment: Alignment.center,
// child: Column(
// children: [
// Container(
// width: 215 / 3.7,
// height: 950 / 3.7 / 3,
// decoration: BoxDecoration(
// border: Border(
// bottom: BorderSide(
// color: Colors.black,
// width: 0.5,
// )),
// ),
// alignment: Alignment.center,
// child: RotatedBox(
// quarterTurns: 3,
// child: Text(
// country,
// style: TextStyle(
// color: Colors.black,
// fontSize: 17,
// fontWeight: FontWeight.bold),
// ),
// ),
// ),
// Container(
// width: 215 / 3.7,
// height: 950 / 3.7 / 3 * 2 - 4,
// padding: EdgeInsets.symmetric(vertical: 10),
// alignment: Alignment.center,
// child: RotatedBox(
// quarterTurns: 3,
// child: Text(
// channel,
// style: TextStyle(
// color: Colors.black,
// fontSize: 15,
// ),
// ),
// ),
// )
// ],
// )
),
Container(
width: 358 / 3.7 -30,
height: 950 / 3.7,
alignment: Alignment.center,
child: Column(
children: [
// Container(
// width: 358 / 3.7 -20,
// height: 950 / 3.7 / 3,
// decoration: BoxDecoration(
// border: Border(
// bottom: BorderSide(
// color: Colors.black,
// width: 0.5,
// )),
// ),
// alignment: Alignment.center,
// child: RotatedBox(
// quarterTurns: 3,
// child: Text(
// countStr,
// style: TextStyle(
// color: Colors.black,
// fontSize: 17,
// fontWeight: FontWeight.bold),
// ),
// ),
// ),
// Container(
// width: 358 / 3.7 -30,
// height: 950 / 3.7 / 3 * 2 - 1.5,
// padding: EdgeInsets.only(left: 15,top: 15,bottom: 15,right: 10) ,
// child: RotatedBox(
// quarterTurns: 3,
// child: BarcodeWidget(
//
// barcode: Barcode.code128(),
// data: code,
// style: TextStyle(
// fontSize: 10
// ),
// ),
// ),
// )
],
)),
],
),
);
}
}

@ -5,49 +5,63 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.8.2"
barcode:
dependency: transitive
description:
name: barcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.1"
barcode_widget:
dependency: "direct main"
description:
name: barcode_widget
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.2"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.16.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
flutter:
@ -55,11 +69,18 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_image_compress:
dependency: "direct main"
description:
name: flutter_image_compress
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
flutter_test:
@ -71,37 +92,44 @@ packages:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.4"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.1"
qr:
dependency: transitive
description:
name: qr
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.1"
sky_engine:
dependency: transitive
description: flutter
@ -111,51 +139,58 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.2"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.9"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.2"
widget_to_image:
dependency: "direct main"
description:
name: widget_to_image
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
sdks:
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.20.0"
flutter: ">=2.0.0"

@ -11,11 +11,16 @@ dependencies:
flutter:
sdk: flutter
widget_to_image: ^2.0.0
barcode_widget: ^2.0.2
flutter_image_compress: ^1.1.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Loading…
Cancel
Save