| 1234567891011121314151617181920212223242526272829303132333435 |
- import 'dart:io';
- import 'package:flutter/services.dart';
- class BluetoothPlugin {
- factory BluetoothPlugin() => _instance;
- BluetoothPlugin._();
- static final BluetoothPlugin _instance = BluetoothPlugin._();
- static BluetoothPlugin get instance => _instance;
- final MethodChannel _channel = const MethodChannel("io.flutter.plugins/bluetooth");
- //开始扫描
- Future<int> startScan() async {
- if (Platform.isIOS) {
- return 0;
- }
- return _channel.invokeMethod('startScan').then<int>((d) => d);
- }
- //设备是否支持蓝牙
- Future<bool> isSupportBle() async {
- if (Platform.isIOS) {
- return true;
- }
- return _channel.invokeMethod('isSupportBle').then<bool>((d) => d);
- }
- //打开蓝牙
- Future open() async {
- if (Platform.isAndroid) {
- _channel.invokeMethod('open');
- }
- }
- }
|