import 'package:flutter/services.dart'; class BluetoothUtils { static const mChannel = const MethodChannel('io.fivefire/method_channel'); static const eChannel = const EventChannel("io.fivefire/event_channel"); Future isBTDevice() async {//检查本机是否有蓝牙设备 try { return await mChannel.invokeMethod('isBTDevice'); } on PlatformException catch (e) { print("$e"); return false; } } Future isEnableBluetooth() async {//打开蓝牙 try { return await mChannel.invokeMethod('isEnableBluetooth'); } on PlatformException catch (e) { print("$e"); return false; } } Future scanBT() async {//开始搜索蓝牙设备 try { return await mChannel.invokeMethod('scanBT'); } on PlatformException catch (e) { print("$e"); } } Future connnectBT(String address) async { try { Map map = {"address": address}; return await mChannel.invokeMethod('connnectBT', map); } on PlatformException catch (e) { print("$e"); } } Future disConnnectBT() async { try { return await mChannel.invokeMethod('disConnectBT'); } on PlatformException catch (e) { print("$e"); } } Future cancelDiscoveryBT() async { try { return await mChannel.invokeMethod('cancelDiscoveryBT'); } on PlatformException catch (e) { print("$e"); } } Future printOrder(Map pum,int type)async{ try { Map map = {"pum":pum,"type": type}; return await mChannel.invokeMethod('printOrder', map); } on PlatformException catch (e) { print("$e"); } } EventChannel getEchannel(){ return eChannel; } // void initState() { // eChannel.receiveBroadcastStream().listen(onEvent, onError: onError); // } // onEvent(Object obj){ // print(obj); // } // onError(Object obj) {} }