global.dart 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import 'package:get/get.dart';
  2. import 'package:vnote_device_plugin/events/event_center.dart';
  3. import 'package:vnote_device_plugin/vnote_device_plugin_platform_interface.dart';
  4. import 'package:vnote_device_plugin/events/global_event_handler.dart';
  5. import 'package:vnote_device_plugin/consts/status.dart';
  6. import 'package:fis_common/logger/logger.dart';
  7. abstract class Global {
  8. static Future<void> init() async {
  9. await logger.init();
  10. await VnoteDevicePluginPlatform.instance.init(false);
  11. // final myListener = DeviceEventListener(
  12. // accpetStatusList: null, // 不传监听全部
  13. // callback: (int status, Map<String, dynamic>? data) {
  14. // logger.i("DEVIC_STATUS: $status");
  15. // },
  16. // );
  17. // DeviceEventCenter.instance.addListener(myListener);
  18. GlobalDeviceEventHandler.setup(statusHandlers: [
  19. DeviceStatusTipsHandler(
  20. VDeviceEventStatus.PERMISSION_OFF_BT, "权限-BLUETOOTH 未开启"),
  21. DeviceStatusTipsHandler(
  22. VDeviceEventStatus.PERMISSION_OFF_BT_ADMIN, "权限-BLUETOOTH_ADMIN 未开启"),
  23. DeviceStatusTipsHandler(VDeviceEventStatus.PERMISSION_OFF_FINE_LOCATION,
  24. "权限-ACCESS_FINE_LOCATION 未开启"),
  25. DeviceStatusTipsHandler(VDeviceEventStatus.PERMISSION_OFF_COARSE_LOCATION,
  26. "权限-ACCESS_COARSE_LOCATION 未开启"),
  27. DeviceStatusTipsHandler(
  28. VDeviceEventStatus.PERMISSION_OFF_BT_SCAN, "权限-BLUETOOTH_SCAN 未开启"),
  29. DeviceStatusTipsHandler(VDeviceEventStatus.PERMISSION_OFF_BT_ADVERTISE,
  30. "权限-BLUETOOTH_ADVERTISE 未开启"),
  31. DeviceStatusTipsHandler(VDeviceEventStatus.PERMISSION_OFF_BT_CONNECT,
  32. "权限-BLUETOOTH_CONNECT 未开启"),
  33. DeviceStatusTipsHandler(
  34. VDeviceEventStatus.CALLBACK_UNDEFINED, "外设SDK-未注册回调接口"),
  35. DeviceStatusTipsHandler(VDeviceEventStatus.PARAM_ERROR, "外设SDK-参数传递错误"),
  36. DeviceStatusTipsHandler(
  37. VDeviceEventStatus.DEVICE_UNSUPPORT, "不支持该型号设备驱动"),
  38. DeviceStatusTipsHandler(VDeviceEventStatus.BLE_NOT_ON, "蓝牙未开启"),
  39. DeviceStatusTipsHandler(
  40. VDeviceEventStatus.BLUETOOTH_CONNECTED_NO_NOTIFY, "蓝牙连接成功,注册通知失败"),
  41. DeviceStatusTipsHandler(
  42. VDeviceEventStatus.DEVICE_NOT_MATCHED, "该蓝牙设备需要绑定配对"),
  43. DeviceStatusTipsHandler(
  44. VDeviceEventStatus.DEVICE_MAC_INVALID, "蓝牙Mac地址无效"),
  45. ]);
  46. }
  47. }
  48. class DeviceStatusTipsHandler extends DeviceEventStatusHandler {
  49. late final String _msg;
  50. DeviceStatusTipsHandler(int status, String msg) : super(status) {
  51. _msg = msg;
  52. }
  53. String get message => _msg;
  54. @override
  55. void handle(Map<String, dynamic>? data) {
  56. Get.snackbar("提示", message);
  57. }
  58. }