|
|
@ -12,9 +12,9 @@ class DjPrinter {
|
|
|
|
static const MethodChannel _channel = MethodChannel('dj_printer');
|
|
|
|
static const MethodChannel _channel = MethodChannel('dj_printer');
|
|
|
|
static const EventChannel _deviceChannel =
|
|
|
|
static const EventChannel _deviceChannel =
|
|
|
|
EventChannel("com.discovery.devices");
|
|
|
|
EventChannel("com.discovery.devices");
|
|
|
|
static StreamSubscription? _discoveryStream;
|
|
|
|
StreamSubscription? _discoveryStream;
|
|
|
|
|
|
|
|
|
|
|
|
static Future<StreamSubscription> addDiscoveryListen(
|
|
|
|
Future<StreamSubscription> addDiscoveryListen(
|
|
|
|
{required void Function(dynamic data) onReceive,
|
|
|
|
{required void Function(dynamic data) onReceive,
|
|
|
|
void Function()? onStart,
|
|
|
|
void Function()? onStart,
|
|
|
|
void Function()? onFinish}) async {
|
|
|
|
void Function()? onFinish}) async {
|
|
|
@ -33,7 +33,7 @@ class DjPrinter {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void cancelDiscovery() {
|
|
|
|
void cancelDiscovery() {
|
|
|
|
if (_discoveryStream != null) {
|
|
|
|
if (_discoveryStream != null) {
|
|
|
|
_discoveryStream!.cancel();
|
|
|
|
_discoveryStream!.cancel();
|
|
|
|
_discoveryStream = null;
|
|
|
|
_discoveryStream = null;
|
|
|
@ -41,9 +41,9 @@ class DjPrinter {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const EventChannel _connectChannel = EventChannel("com.connect");
|
|
|
|
static const EventChannel _connectChannel = EventChannel("com.connect");
|
|
|
|
static StreamSubscription? _connectStream;
|
|
|
|
StreamSubscription? _connectStream;
|
|
|
|
|
|
|
|
|
|
|
|
static Future<StreamSubscription> addConnectListen(
|
|
|
|
Future<StreamSubscription> addConnectListen(
|
|
|
|
{required void Function() onConnect,
|
|
|
|
{required void Function() onConnect,
|
|
|
|
required void Function() onDisconnect}) async {
|
|
|
|
required void Function() onDisconnect}) async {
|
|
|
|
if (_connectStream == null) {
|
|
|
|
if (_connectStream == null) {
|
|
|
@ -59,24 +59,24 @@ class DjPrinter {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void cancelConnect() {
|
|
|
|
void cancelConnect() {
|
|
|
|
if (_connectStream != null) {
|
|
|
|
if (_connectStream != null) {
|
|
|
|
_connectStream!.cancel();
|
|
|
|
_connectStream!.cancel();
|
|
|
|
_connectStream = null;
|
|
|
|
_connectStream = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Future<bool?> get startSearch async {
|
|
|
|
Future<bool?> get startSearch async {
|
|
|
|
final res = await _channel.invokeMethod('startSearch');
|
|
|
|
final res = await _channel.invokeMethod('startSearch');
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Future<bool?> connect(String address) async {
|
|
|
|
Future<bool?> connect(String address) async {
|
|
|
|
final res = await _channel.invokeMethod('connect', {'address': address});
|
|
|
|
final res = await _channel.invokeMethod('connect', {'address': address});
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Future<bool?> init() async {
|
|
|
|
Future<bool?> init() async {
|
|
|
|
final res = await _channel.invokeMethod('init');
|
|
|
|
final res = await _channel.invokeMethod('init');
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -86,7 +86,7 @@ class DjPrinter {
|
|
|
|
//2 paper empty
|
|
|
|
//2 paper empty
|
|
|
|
//4 cover open
|
|
|
|
//4 cover open
|
|
|
|
//8 battery low
|
|
|
|
//8 battery low
|
|
|
|
static Future<PRINT_STATUS?> getStatus() async {
|
|
|
|
Future<PRINT_STATUS?> getStatus() async {
|
|
|
|
final res = await _channel.invokeMethod('getStatus');
|
|
|
|
final res = await _channel.invokeMethod('getStatus');
|
|
|
|
switch (res) {
|
|
|
|
switch (res) {
|
|
|
|
case 0:
|
|
|
|
case 0:
|
|
|
@ -104,7 +104,7 @@ class DjPrinter {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Future<bool?> print(
|
|
|
|
Future<bool?> print(
|
|
|
|
{required String code,
|
|
|
|
{required String code,
|
|
|
|
required String channel,
|
|
|
|
required String channel,
|
|
|
|
required String country,
|
|
|
|
required String country,
|
|
|
|