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 enableBluetooth() async { try { return await mChannel.invokeMethod('enableBluetooth'); } on PlatformException catch (e) { print("$e"); return false; } } /** * 扫描蓝牙设备 */ Future scanBT() async { try { return await mChannel.invokeMethod('scanBT'); } on PlatformException catch (e) { print("$e"); } } /** * 传入mac 地址 * 连接蓝牙 */ Future connectBT(String address) async { try { Map map = {"address": address}; return await mChannel.invokeMethod('connectBT', 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"); } } Future isConnect(String address) async { try { Map map = {"address": address}; return await mChannel.invokeMethod('connectBT', map); } on PlatformException catch (e) { print("$e"); } } EventChannel getEchannel(){ return eChannel; } }