-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathflutter_blue_plus_wrapper.dart
133 lines (115 loc) · 4.63 KB
/
flutter_blue_plus_wrapper.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import 'dart:async';
import 'dart:io';
import 'package:flutter_blue_plus/flutter_blue_plus.dart' as FBP;
import 'package:flutter_blue_plus_windows/flutter_blue_plus_windows.dart';
class FlutterBluePlus {
static Future<void> startScan({
List<Guid> withServices = const [],
List<String> withRemoteIds = const [],
List<String> withNames = const [],
List<String> withKeywords = const [],
List<MsdFilter> withMsd = const [],
List<ServiceDataFilter> withServiceData = const [],
Duration? timeout,
Duration? removeIfGone,
bool continuousUpdates = false,
int continuousDivisor = 1,
bool oneByOne = false,
bool androidLegacy = false,
AndroidScanMode androidScanMode = AndroidScanMode.lowLatency,
bool androidUsesFineLocation = false,
}) async {
if (Platform.isWindows) {
return await FlutterBluePlusWindows.startScan(
withServices: withServices,
withRemoteIds: withRemoteIds,
withNames: withNames,
withKeywords: withKeywords,
withMsd: withMsd,
withServiceData: withServiceData,
timeout: timeout,
removeIfGone: removeIfGone,
continuousUpdates: continuousUpdates,
continuousDivisor: continuousDivisor,
oneByOne: oneByOne,
androidLegacy: androidLegacy,
androidScanMode: androidScanMode,
androidUsesFineLocation: androidUsesFineLocation,
);
}
return await FBP.FlutterBluePlus.startScan(
withServices: withServices,
withRemoteIds: withRemoteIds,
withNames: withNames,
withKeywords: withKeywords,
withMsd: withMsd,
withServiceData: withServiceData,
timeout: timeout,
removeIfGone: removeIfGone,
continuousUpdates: continuousUpdates,
continuousDivisor: continuousDivisor,
oneByOne: oneByOne,
androidLegacy: androidLegacy,
androidScanMode: androidScanMode,
androidUsesFineLocation: androidUsesFineLocation,
);
}
static Stream<BluetoothAdapterState> get adapterState {
if (Platform.isWindows) return FlutterBluePlusWindows.adapterState;
return FBP.FlutterBluePlus.adapterState;
}
static Stream<List<ScanResult>> get scanResults {
if (Platform.isWindows) return FlutterBluePlusWindows.scanResults;
return FBP.FlutterBluePlus.scanResults;
}
static bool get isScanningNow {
if (Platform.isWindows) return FlutterBluePlusWindows.isScanningNow;
return FBP.FlutterBluePlus.isScanningNow;
}
static Stream<bool> get isScanning {
if (Platform.isWindows) return FlutterBluePlusWindows.isScanning;
return FBP.FlutterBluePlus.isScanning;
}
static Future<void> stopScan() async {
if (Platform.isWindows) return await FlutterBluePlusWindows.stopScan();
return await FBP.FlutterBluePlus.stopScan();
}
static Future<void> setLogLevel(LogLevel level, {color = true}) async {
if (Platform.isWindows) return FlutterBluePlusWindows.setLogLevel(level, color: color);
return FBP.FlutterBluePlus.setLogLevel(level, color: color);
}
/// TODO: need to verify
static LogLevel get logLevel => FBP.FlutterBluePlus.logLevel;
static Future<bool> get isSupported async {
if (Platform.isWindows) return await FlutterBluePlusWindows.isSupported;
return await FBP.FlutterBluePlus.isSupported;
}
static Future<String> get adapterName async {
if (Platform.isWindows) return await FlutterBluePlusWindows.adapterName;
return await FBP.FlutterBluePlus.adapterName;
}
static Future<void> turnOn({int timeout = 60}) async {
if (Platform.isWindows) return await FlutterBluePlusWindows.turnOn(timeout: timeout);
return await FBP.FlutterBluePlus.turnOn(timeout: timeout);
}
static List<FBP.BluetoothDevice> get connectedDevices {
if (Platform.isWindows) return FlutterBluePlusWindows.connectedDevices;
return FBP.FlutterBluePlus.connectedDevices;
}
static Future<List<FBP.BluetoothDevice>> systemDevices(List<Guid> withServices) async {
//TODO: connected devices => system devices
if (Platform.isWindows) return FlutterBluePlusWindows.connectedDevices;
return await FBP.FlutterBluePlus.systemDevices(withServices);
}
static Future<PhySupport> getPhySupport() {
return FBP.FlutterBluePlus.getPhySupport();
}
static Future<List<FBP.BluetoothDevice>> get bondedDevices async {
if (Platform.isWindows) return FlutterBluePlusWindows.connectedDevices;
return await FBP.FlutterBluePlus.bondedDevices;
}
static void cancelWhenScanComplete(StreamSubscription subscription) {
if (Platform.isWindows) return FlutterBluePlusWindows.cancelWhenScanComplete(subscription);
return FBP.FlutterBluePlus.cancelWhenScanComplete(subscription);
}
}