You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.1 KiB
92 lines
2.1 KiB
import 'dart:async';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
class DjScaner {
|
|
static const String scanActionName =
|
|
"com.android.server.scannerservice.asscaner";
|
|
static const MethodChannel _channel = MethodChannel('dj_scaner');
|
|
static const EventChannel _eventChannel =
|
|
EventChannel('com.dj.pda.scaner/scandata');
|
|
static StreamSubscription? _streamSubscription;
|
|
|
|
static Future<StreamSubscription> addListener(
|
|
void Function(dynamic data)? onData) async {
|
|
await scanEnabled(true);
|
|
if (_streamSubscription == null) {
|
|
return _eventChannel.receiveBroadcastStream().listen(onData);
|
|
} else {
|
|
return _streamSubscription!;
|
|
}
|
|
}
|
|
|
|
static void cancel() {
|
|
if (_streamSubscription != null) {
|
|
_streamSubscription!.cancel();
|
|
_streamSubscription = null;
|
|
}
|
|
scanEnabled(false);
|
|
}
|
|
|
|
static Future init() async {
|
|
|
|
///默认关闭声音
|
|
await soundPlay(false);
|
|
|
|
///默认关闭震动
|
|
await viberate(false);
|
|
|
|
///默认开机自启动
|
|
await bootStart(true);
|
|
|
|
///设置广播名称
|
|
await broadcastName(scanActionName);
|
|
|
|
///默认关闭扫描
|
|
await scanEnabled(false);
|
|
print('扫描初始化完成');
|
|
}
|
|
|
|
///声音开关
|
|
static Future soundPlay(bool onOpen) async {
|
|
await _channel.invokeMethod('soundPlay', {
|
|
'onOpen': onOpen,
|
|
});
|
|
}
|
|
|
|
///震动开关
|
|
static Future viberate(bool onOpen) async {
|
|
await _channel.invokeMethod('viberate', {
|
|
'onOpen': onOpen,
|
|
});
|
|
}
|
|
|
|
///连续扫描开关
|
|
static Future scanContinue(bool onOpen) async {
|
|
await _channel.invokeMethod('scanContinue', {
|
|
'onOpen': onOpen,
|
|
});
|
|
}
|
|
|
|
///开机自启动
|
|
static Future bootStart(bool onOpen) async {
|
|
await _channel.invokeMethod('bootStart', {
|
|
'onOpen': onOpen,
|
|
});
|
|
}
|
|
|
|
///启动/禁用扫描头
|
|
static Future scanEnabled(bool onOpen) async {
|
|
await _channel.invokeMethod('scanEnabled', {
|
|
'onOpen': onOpen,
|
|
});
|
|
}
|
|
|
|
///设置广播名称
|
|
static Future broadcastName(String name) async {
|
|
await _channel.invokeMethod('broadcastName', {
|
|
'name': name,
|
|
});
|
|
}
|
|
}
|