更改名称

master
张萌 2 years ago
parent 3d16fd8ee1
commit 81e0daf448

@ -0,0 +1,204 @@
<component name="libraryTable">
<library name="Dart Packages" type="DartPackagesLibraryType">
<properties>
<option name="packageNameToDirsMap">
<entry key="async">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/async-2.9.0/lib" />
</list>
</value>
</entry>
<entry key="boolean_selector">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib" />
</list>
</value>
</entry>
<entry key="bot_toast">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/bot_toast-4.0.3/lib" />
</list>
</value>
</entry>
<entry key="characters">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/characters-1.2.1/lib" />
</list>
</value>
</entry>
<entry key="clock">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/clock-1.1.1/lib" />
</list>
</value>
</entry>
<entry key="collection">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/collection-1.16.0/lib" />
</list>
</value>
</entry>
<entry key="cupertino_icons">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/cupertino_icons-1.0.5/lib" />
</list>
</value>
</entry>
<entry key="fake_async">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/fake_async-1.3.1/lib" />
</list>
</value>
</entry>
<entry key="flutter">
<value>
<list>
<option value="$PROJECT_DIR$/../fvm/versions/3.3.0/packages/flutter/lib" />
</list>
</value>
</entry>
<entry key="flutter_lints">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/flutter_lints-1.0.4/lib" />
</list>
</value>
</entry>
<entry key="flutter_test">
<value>
<list>
<option value="$PROJECT_DIR$/../fvm/versions/3.3.0/packages/flutter_test/lib" />
</list>
</value>
</entry>
<entry key="lints">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/lints-1.0.1/lib" />
</list>
</value>
</entry>
<entry key="matcher">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/matcher-0.12.12/lib" />
</list>
</value>
</entry>
<entry key="material_color_utilities">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/material_color_utilities-0.1.5/lib" />
</list>
</value>
</entry>
<entry key="meta">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/meta-1.8.0/lib" />
</list>
</value>
</entry>
<entry key="path">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/path-1.8.2/lib" />
</list>
</value>
</entry>
<entry key="sky_engine">
<value>
<list>
<option value="$PROJECT_DIR$/../fvm/versions/3.3.0/bin/cache/pkg/sky_engine/lib" />
</list>
</value>
</entry>
<entry key="source_span">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/source_span-1.9.0/lib" />
</list>
</value>
</entry>
<entry key="stack_trace">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/stack_trace-1.10.0/lib" />
</list>
</value>
</entry>
<entry key="stream_channel">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/stream_channel-2.1.0/lib" />
</list>
</value>
</entry>
<entry key="string_scanner">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/string_scanner-1.1.1/lib" />
</list>
</value>
</entry>
<entry key="term_glyph">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/term_glyph-1.2.1/lib" />
</list>
</value>
</entry>
<entry key="test_api">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/test_api-0.4.12/lib" />
</list>
</value>
</entry>
<entry key="vector_math">
<value>
<list>
<option value="$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.2/lib" />
</list>
</value>
</entry>
</option>
</properties>
<CLASSES>
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/async-2.9.0/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/bot_toast-4.0.3/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/characters-1.2.1/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/clock-1.1.1/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/collection-1.16.0/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/cupertino_icons-1.0.5/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/fake_async-1.3.1/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/flutter_lints-1.0.4/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/lints-1.0.1/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/matcher-0.12.12/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/material_color_utilities-0.1.5/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/meta-1.8.0/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/path-1.8.2/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/source_span-1.9.0/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/stack_trace-1.10.0/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/stream_channel-2.1.0/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/string_scanner-1.1.1/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/term_glyph-1.2.1/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/test_api-0.4.12/lib" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.2/lib" />
<root url="file://$PROJECT_DIR$/../fvm/versions/3.3.0/bin/cache/pkg/sky_engine/lib" />
<root url="file://$PROJECT_DIR$/../fvm/versions/3.3.0/packages/flutter/lib" />
<root url="file://$PROJECT_DIR$/../fvm/versions/3.3.0/packages/flutter_test/lib" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -1,8 +1,6 @@
<component name="libraryTable">
<library name="Flutter Plugins" type="FlutterPluginsLibraryType">
<CLASSES>
<root url="file://$PROJECT_DIR$" />
</CLASSES>
<CLASSES />
<JAVADOC />
<SOURCES />
</library>

@ -3,7 +3,7 @@ import 'dart:convert';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:hy_printer/device.dart';
import 'package:hy_printer/dj_printer.dart';
import 'package:hy_printer/hy_printer.dart';
import 'package:hy_printer/hy_printer.dart';
import 'package:hy_printer_example/scan_page.dart';
// import 'package:permission_handler/permission_handler.dart';
@ -30,8 +30,8 @@ class _MyAppState extends State<MyApp> {
Future<void> initPlatformState() async {
DjPrinter().init();
DjPrinter().addDiscoveryListen(onReceive: (data) {
HyPrinter().init();
HyPrinter().addDiscoveryListen(onReceive: (data) {
var js = json.decode(data.toString());
if ((js['name'] as String).startsWith('HM')) {
devices.add(Device(
@ -44,10 +44,10 @@ class _MyAppState extends State<MyApp> {
print("————————————————————————");
}, onFinish: () {
print('——————————————————————————————');
DjPrinter().cancelDiscovery();
HyPrinter().cancelDiscovery();
cancel();
});
DjPrinter().addConnectListen(onConnect: () {
HyPrinter().addConnectListen(onConnect: () {
print("connected");
}, onDisconnect: () {
print('disconnected');
@ -82,7 +82,7 @@ class _MyAppState extends State<MyApp> {
BotToast.showLoading(wrapToastAnimation: (controller, func, child) {
return discoveryLoadingWidget();
});
DjPrinter().startSearch;
HyPrinter().startSearch;
},
child: const Text('扫描设备')),
// TextButton(onPressed: () {}, child: const Text('打印')),
@ -97,7 +97,7 @@ class _MyAppState extends State<MyApp> {
});
await DjPrinter().connect(e.address).then((value) {
await HyPrinter().connect(e.address).then((value) {
print("main value result");
print(value);
if(value!=null&&value){
@ -124,7 +124,7 @@ class _MyAppState extends State<MyApp> {
),
TextButton(
onPressed: () {
DjPrinter().printNewAScode(
HyPrinter().printNewAScode(
code: 'ASSZ000000002',
barCode: 'ASSZ0000000020001',
channel: '加拿大温哥华海派快线-卡派 / UPS派送',
@ -138,7 +138,7 @@ class _MyAppState extends State<MyApp> {
TextButton(
onPressed: () {
DjPrinter().printNewAScode(
HyPrinter().printNewAScode(
code: 'ASSZ000000002',
barCode: 'ASSZ0000000020001',
channel: '加拿大温哥华海派快线-卡派 / UPS派送',
@ -154,7 +154,7 @@ class _MyAppState extends State<MyApp> {
),
TextButton(
onPressed: () {
DjPrinter().disposeConnect();
HyPrinter().disposeConnect();
},
child: const Text('取消链接')),

@ -3,7 +3,7 @@ import 'dart:convert';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:hy_printer/device.dart';
import 'package:hy_printer/dj_printer.dart';
import 'package:hy_printer/hy_printer.dart';
import 'package:hy_printer/hy_printer.dart';
class ScanPage extends StatefulWidget {
@ -44,8 +44,8 @@ class _ScanPageState extends State<ScanPage> {
// Permission.bluetoothConnect.request();
// }
DjPrinter().init();
DjPrinter().addDiscoveryListen(onReceive: (data) {
HyPrinter().init();
HyPrinter().addDiscoveryListen(onReceive: (data) {
var js = json.decode(data.toString());
if ((js['name'] as String).startsWith('HM')) {
devices.add(Device(
@ -61,10 +61,10 @@ class _ScanPageState extends State<ScanPage> {
print("————————————————————————");
}, onFinish: () {
print('——————————————————————————————');
DjPrinter().cancelDiscovery();
HyPrinter().cancelDiscovery();
cancel();
});
DjPrinter().addConnectListen(onConnect: () {
HyPrinter().addConnectListen(onConnect: () {
print("connected");
}, onDisconnect: () {
print('disconnected');
@ -93,7 +93,7 @@ class _ScanPageState extends State<ScanPage> {
BotToast.showLoading(wrapToastAnimation: (controller, func, child) {
return discoveryLoadingWidget();
});
DjPrinter().startSearch;
HyPrinter().startSearch;
},
child: const Text('扫描设备')),
// TextButton(onPressed: () {}, child: const Text('打印')),
@ -104,7 +104,7 @@ class _ScanPageState extends State<ScanPage> {
.map((e) => TextButton(
onPressed: ()async {
await DjPrinter().connect(e.address);
await HyPrinter().connect(e.address);
},
@ -120,7 +120,7 @@ class _ScanPageState extends State<ScanPage> {
),
TextButton(
onPressed: () {
DjPrinter().printNewAScode(
HyPrinter().printNewAScode(
code: 'ASSZ000000002',
barCode: 'ASSZ0000000020001',
channel: '加拿大温哥华海派快线-卡派 / UPS派送',
@ -134,7 +134,7 @@ class _ScanPageState extends State<ScanPage> {
TextButton(
onPressed: () {
DjPrinter().printNewAScode(
HyPrinter().printNewAScode(
code: 'ASSZ000000002',
barCode: 'ASSZ0000000020001',
channel: '加拿大温哥华海派快线-卡派 / UPS派送',
@ -150,7 +150,7 @@ class _ScanPageState extends State<ScanPage> {
),
TextButton(
onPressed: () {
DjPrinter().disposeConnect();
HyPrinter().disposeConnect();
},
child: const Text('取消链接')),

@ -5,65 +5,58 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
bot_toast:
dependency: "direct main"
description:
name: bot_toast
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.3"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.1"
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
@ -73,7 +66,7 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
flutter_test:
@ -92,37 +85,37 @@ packages:
dependency: transitive
description:
name: lints
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
sky_engine:
dependency: transitive
description: flutter
@ -132,49 +125,49 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
sdks:

@ -17,5 +17,6 @@
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
<orderEntry type="library" name="CPCL_SDK_V1.11" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

@ -1,195 +0,0 @@
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hy_printer/status_enum.dart';
class DjPrinter {
static late final DjPrinter _instance = DjPrinter._();
DjPrinter._();
factory DjPrinter() => _instance;
static const MethodChannel _channel = MethodChannel('hy_printer');
static const EventChannel _deviceChannel =
EventChannel("com.discovery.devices");
StreamSubscription? _discoveryStream;
StreamSubscription addDiscoveryListen(
{required void Function(dynamic data) onReceive,
void Function()? onStart,
void Function()? onFinish}) {
if (_discoveryStream == null) {
return _deviceChannel.receiveBroadcastStream().listen((data) {
if (data == "start" && onStart != null) {
onStart();
} else if (data == "finish" && onFinish != null) {
onFinish();
} else {
onReceive(data);
}
});
} else {
return _discoveryStream!;
}
}
void cancelDiscovery() {
_discoveryStream?.cancel();
_discoveryStream = null;
print('结束搜索');
disposeDiscovery();
}
static const EventChannel _connectChannel = EventChannel("com.connect");
StreamSubscription? _connectStream;
StreamSubscription addConnectListen({required void Function() onConnect,
required void Function() onDisconnect}) {
if (_connectStream == null) {
return _connectChannel.receiveBroadcastStream().listen((data) {
if (data == 'connected') {
onConnect();
} else if (data == 'disconnected') {
onDisconnect();
}
});
} else {
return _connectStream!;
}
}
void cancelConnect() {
if (_connectStream != null) {
_connectStream!.cancel();
_connectStream = null;
}
}
void get startSearch {
final res = _channel.invokeMethod('startSearch');
}
bool _hasInit = false;
bool get hasInit => _hasInit;
Future<bool?> connect(String address) async {
final res = await _channel.invokeMethod('connect', {'address': address});
return res;
}
void disposeDiscovery() {
print('disposeDiscovery');
final res = _channel.invokeMethod('disposeDiscovery');
}
Future<bool?> disposeConnect() async {
final res = await _channel.invokeMethod('disposeConnect');
return res;
}
Future<bool?> init() async {
final res = await _channel.invokeMethod('init');
_hasInit = true;
return res;
}
//0 normal
//1 busy
//2 paper empty
//4 cover open
//8 battery low
// Future<PRINT_STATUS?> getStatus() async {
// final res = await _channel.invokeMethod('getStatus');
// switch (res) {
// case 0:
// return PRINT_STATUS.normal;
// case 1:
// return PRINT_STATUS.busy;
// case 2:
// return PRINT_STATUS.paperEmpty;
// case 4:
// return PRINT_STATUS.coverOpen;
// case 8:
// return PRINT_STATUS.batteryLow;
// default:
// return null;
// }
// }
//0 normal
//-1
//2 paper empty
//6 cover open
Future<PRINT_STATUS?> getStatus() async {
final res = await _channel.invokeMethod('getStatus');
switch (res) {
case 0:
return PRINT_STATUS.normal;
case -1:
return PRINT_STATUS.fail;
case 2:
return PRINT_STATUS.paperEmpty;
case 6:
return PRINT_STATUS.coverOpen;
default:
return null;
}
}
Future<bool?> printNewAScode({required String code,
required String barCode,
required String channel,
required String country,
required String num,
required String sum,
required int offset,
required bool hasPlan}) async {
final res = await _channel.invokeMethod('newPrint', {
'code': code,
'barCode':barCode,
'channel': channel,
'country': country,
'num': num,
'sum': sum,
'offset': offset,
'hasPlan': hasPlan,
});
return res;
}
Future<bool?> printAScode({required String code,
required String channel,
required String country,
required String countStr,
required int offset,
required bool hasPlan}) async {
final res = await _channel.invokeMethod('print', {
'code': code,
'channel': channel,
'country': country,
'countStr': countStr,
'offset': offset,
'hasPlan': hasPlan,
});
return res;
}
}

@ -1,155 +1,191 @@
// import 'dart:async';
//
// import 'package:flutter/services.dart';
// // import 'package:flutter_blue/flutter_blue.dart';
// import 'package:flutter_blue_plus/flutter_blue_plus.dart';
// import 'package:hy_printer/device.dart';
// import 'package:permission_handler/permission_handler.dart';
//
// class HyPrinter {
// static const MethodChannel _channel = MethodChannel('hy_printer');
// static FlutterBluePlus flutterBlue = FlutterBluePlus.instance;
// static void init() async {
// var per = await Permission.bluetooth.isGranted;
// if (!per) {
// Permission.bluetooth.request();
// }
// var pers = await Permission.locationWhenInUse.isGranted;
// if (!pers) {
// Permission.locationWhenInUse.request();
// }
// }
//
// static Future<List<Device>> getDeiveces() async {
// var devices = <Device>[];
// await flutterBlue.startScan(timeout: const Duration(seconds: 4));
// flutterBlue.scanResults.listen((results) {
// for (ScanResult r in results) {
// //
// if(r.device.name.contains('HM')){
// devices.add(Device(name: r.device.name, address: r.device.id.id));
// }
//
// // if (r.device.name.isNotEmpty) {
// // devices.add(Device(name: r.device.name, address: r.device.id.id));
// // }
// }
// });
// await flutterBlue.stopScan();
// return devices;
// }
//
// static Future<bool> blutIsOn() async {
// var result = await flutterBlue.isOn;
// return result;
// }
//
// ///0
// ///-1
// ///-2
// ///-3sdk
// ///-4
// static Future<int> connect(String address) async {
// int result = -4;
// await Future.delayed(const Duration(milliseconds: 2000), () async {
// result = await _channel.invokeMethod('connect', {'address': address});
// });
// // int result = await _channel.invokeMethod('connect', {'address': address});
// return result;
// }
//
// static Future<bool> disConnect() async {
// bool result = await _channel.invokeMethod('disConnect');
// return result;
// }
//
// ///0:
// ///-1
// ///2
// ///3
// static Future<int> getStatus() async {
// int result = await _channel.invokeMethod(
// 'getStatus',
// );
// return result;
// }
//
// static Future<int> printBarCode(
// int direction,
// int type,
// String width,
// String ratio,
// String height,
// String x,
// String y,
// bool undertext,
// String size,
// String offset,
// String data,
// ) async {
// int result = await _channel.invokeMethod('printBarCode', {
// 'direction': direction,
// 'type': type,
// 'width': width,
// 'ratio': ratio,
// 'height': height,
// 'x': x,
// 'y': y,
// 'undertext': undertext,
// 'size': size,
// 'offset': offset,
// 'data': data,
// });
// return result;
// }
//
// static Future<int> printLine(
// String x0,
// String y0,
// String x1,
// String y1,
// ) async {
// int result = await _channel
// .invokeMethod('printLine', {'x0': x0, 'x1': x1, 'y0': y0, 'y1': y1});
// return result;
// }
//
// static Future<int> align(String align) async {
// int result = await _channel.invokeMethod('align', {'align': align});
// return result;
// }
//
// static Future<int> setBold(String bold) async {
// int result = await _channel.invokeMethod('setBold', {'bold': bold});
// return result;
// }
//
// static Future<int> prefeed(String prefeed) async {
// int result = await _channel.invokeMethod('setBold', {'prefeed': prefeed});
// return result;
// }
//
// /// 'code': code,
// // 'fbaCode': fbaCode, fba/fba
// // 'channel': channel,
// // 'country': country,
// // 'count': count,
// // 'hasPlan':hasPlan
// static Future<int> printAsOrder(
// {required String code,
// required String fbaCode,
// required String channel,
// required String country,
// required String count,
// required bool hasPlan}) async {
// int result = await _channel.invokeMethod('printAsOrder', {
// 'code': code,
// 'fbaCode': fbaCode,
// 'channel': channel,
// 'country': country,
// 'count': count,
// 'hasPlan': hasPlan
// });
// return result;
// }
// }
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:hy_printer/status_enum.dart';
class HyPrinter {
static late final HyPrinter _instance = HyPrinter._();
HyPrinter._();
factory HyPrinter() => _instance;
static const MethodChannel _channel = MethodChannel('hy_printer');
static const EventChannel _deviceChannel =
EventChannel("com.discovery.devices");
StreamSubscription? _discoveryStream;
StreamSubscription addDiscoveryListen(
{required void Function(dynamic data) onReceive,
void Function()? onStart,
void Function()? onFinish}) {
if (_discoveryStream == null) {
return _deviceChannel.receiveBroadcastStream().listen((data) {
if (data == "start" && onStart != null) {
onStart();
} else if (data == "finish" && onFinish != null) {
onFinish();
} else {
onReceive(data);
}
});
} else {
return _discoveryStream!;
}
}
void cancelDiscovery() {
_discoveryStream?.cancel();
_discoveryStream = null;
print('结束搜索');
disposeDiscovery();
}
static const EventChannel _connectChannel = EventChannel("com.connect");
StreamSubscription? _connectStream;
StreamSubscription addConnectListen({required void Function() onConnect,
required void Function() onDisconnect}) {
if (_connectStream == null) {
return _connectChannel.receiveBroadcastStream().listen((data) {
if (data == 'connected') {
onConnect();
} else if (data == 'disconnected') {
onDisconnect();
}
});
} else {
return _connectStream!;
}
}
void cancelConnect() {
if (_connectStream != null) {
_connectStream!.cancel();
_connectStream = null;
}
}
void get startSearch {
final res = _channel.invokeMethod('startSearch');
}
bool _hasInit = false;
bool get hasInit => _hasInit;
Future<bool?> connect(String address) async {
final res = await _channel.invokeMethod('connect', {'address': address});
return res;
}
void disposeDiscovery() {
print('disposeDiscovery');
final res = _channel.invokeMethod('disposeDiscovery');
}
Future<bool?> disposeConnect() async {
final res = await _channel.invokeMethod('disposeConnect');
return res;
}
Future<bool?> init() async {
final res = await _channel.invokeMethod('init');
_hasInit = true;
return res;
}
//0 normal
//1 busy
//2 paper empty
//4 cover open
//8 battery low
// Future<PRINT_STATUS?> getStatus() async {
// final res = await _channel.invokeMethod('getStatus');
// switch (res) {
// case 0:
// return PRINT_STATUS.normal;
// case 1:
// return PRINT_STATUS.busy;
// case 2:
// return PRINT_STATUS.paperEmpty;
// case 4:
// return PRINT_STATUS.coverOpen;
// case 8:
// return PRINT_STATUS.batteryLow;
// default:
// return null;
// }
// }
//0 normal
//-1
//2 paper empty
//6 cover open
Future<PRINT_STATUS?> getStatus() async {
final res = await _channel.invokeMethod('getStatus');
switch (res) {
case 0:
return PRINT_STATUS.normal;
case -1:
return PRINT_STATUS.fail;
case 2:
return PRINT_STATUS.paperEmpty;
case 6:
return PRINT_STATUS.coverOpen;
default:
return null;
}
}
Future<bool?> printNewAScode({required String code,
required String barCode,
required String channel,
required String country,
required String num,
required String sum,
required int offset,
required bool hasPlan}) async {
final res = await _channel.invokeMethod('newPrint', {
'code': code,
'barCode':barCode,
'channel': channel,
'country': country,
'num': num,
'sum': sum,
'offset': offset,
'hasPlan': hasPlan,
});
return res;
}
Future<bool?> printAScode({required String code,
required String channel,
required String country,
required String countStr,
required int offset,
required bool hasPlan}) async {
final res = await _channel.invokeMethod('print', {
'code': code,
'channel': channel,
'country': country,
'countStr': countStr,
'offset': offset,
'hasPlan': hasPlan,
});
return res;
}
}

@ -5,51 +5,44 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.1"
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
@ -59,7 +52,7 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
flutter_test:
@ -71,37 +64,37 @@ packages:
dependency: transitive
description:
name: lints
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
sky_engine:
dependency: transitive
description: flutter
@ -111,49 +104,49 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
sdks:

Loading…
Cancel
Save