1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import 'package:get/get.dart';
- import 'package:vnote_device_plugin/events/event_center.dart';
- import 'package:vnote_device_plugin/vnote_device_plugin_platform_interface.dart';
- import 'package:vnote_device_plugin/events/global_event_handler.dart';
- import 'package:vnote_device_plugin/consts/status.dart';
- import 'package:fis_common/logger/logger.dart';
- abstract class Global {
- static Future<void> init() async {
- await logger.init();
- await VnoteDevicePluginPlatform.instance.init(false);
- // final myListener = DeviceEventListener(
- // accpetStatusList: null, // 不传监听全部
- // callback: (int status, Map<String, dynamic>? data) {
- // logger.i("DEVIC_STATUS: $status");
- // },
- // );
- // DeviceEventCenter.instance.addListener(myListener);
- GlobalDeviceEventHandler.setup(statusHandlers: [
- DeviceStatusTipsHandler(
- VDeviceEventStatus.PERMISSION_OFF_BT, "权限-BLUETOOTH 未开启"),
- DeviceStatusTipsHandler(
- VDeviceEventStatus.PERMISSION_OFF_BT_ADMIN, "权限-BLUETOOTH_ADMIN 未开启"),
- DeviceStatusTipsHandler(VDeviceEventStatus.PERMISSION_OFF_FINE_LOCATION,
- "权限-ACCESS_FINE_LOCATION 未开启"),
- DeviceStatusTipsHandler(VDeviceEventStatus.PERMISSION_OFF_COARSE_LOCATION,
- "权限-ACCESS_COARSE_LOCATION 未开启"),
- DeviceStatusTipsHandler(
- VDeviceEventStatus.PERMISSION_OFF_BT_SCAN, "权限-BLUETOOTH_SCAN 未开启"),
- DeviceStatusTipsHandler(VDeviceEventStatus.PERMISSION_OFF_BT_ADVERTISE,
- "权限-BLUETOOTH_ADVERTISE 未开启"),
- DeviceStatusTipsHandler(VDeviceEventStatus.PERMISSION_OFF_BT_CONNECT,
- "权限-BLUETOOTH_CONNECT 未开启"),
- DeviceStatusTipsHandler(
- VDeviceEventStatus.CALLBACK_UNDEFINED, "外设SDK-未注册回调接口"),
- DeviceStatusTipsHandler(VDeviceEventStatus.PARAM_ERROR, "外设SDK-参数传递错误"),
- DeviceStatusTipsHandler(
- VDeviceEventStatus.DEVICE_UNSUPPORT, "不支持该型号设备驱动"),
- DeviceStatusTipsHandler(VDeviceEventStatus.BLE_NOT_ON, "蓝牙未开启"),
- DeviceStatusTipsHandler(
- VDeviceEventStatus.BLUETOOTH_CONNECTED_NO_NOTIFY, "蓝牙连接成功,注册通知失败"),
- DeviceStatusTipsHandler(
- VDeviceEventStatus.DEVICE_NOT_MATCHED, "该蓝牙设备需要绑定配对"),
- DeviceStatusTipsHandler(
- VDeviceEventStatus.DEVICE_MAC_INVALID, "蓝牙Mac地址无效"),
- ]);
- }
- }
- class DeviceStatusTipsHandler extends DeviceEventStatusHandler {
- late final String _msg;
- DeviceStatusTipsHandler(int status, String msg) : super(status) {
- _msg = msg;
- }
- String get message => _msg;
- @override
- void handle(Map<String, dynamic>? data) {
- Get.snackbar("提示", message);
- }
- }
|