| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- 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<bool> isBTDevice() async {//检查本机是否有蓝牙设备
- try {
- return await mChannel.invokeMethod('isBTDevice');
- } on PlatformException catch (e) {
- print("$e");
- return false;
- }
- }
- Future<bool> 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<Null> connnectBT(String address) async {
- try {
- Map<String, String> 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 printOrder(Map<String,String> pum,int type)async{
- try {
- Map<String,Object> 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) {}
-
- }
|