Allow pairing on all platforms

Mark Web/Linux as not supporting in-app pairing
This commit is contained in:
Foti Dim
2024-09-18 06:49:11 +02:00
committed by GitHub
parent 7dc22c58a5
commit 694262d9a9
2 changed files with 11 additions and 6 deletions
+10 -2
View File
@@ -2,12 +2,20 @@ import 'package:flutter/foundation.dart';
class BleCapabilities {
/// Returns true if pairing is possible either by API or by encrypted characteristic.
/// All platforms support this except Windows/Web.
///
/// All platforms support this except Web/Windows and Web/Linux.
///
/// On `Web/Windows` and `Web/Linux` it is known to only work for devices that require passkey pairing.
/// If your device requires passkey pairing you can consider this true for all platforms.
///
/// `Web/Linux` could under certain circumstances present a pairing dialog also for devices that do
/// not use passkey pairing but it very unreliable so we consider it unsupported.
static final bool supportsInAppPairing =
_triggersPairingWithEncryptedChar || hasSystemPairingApi;
static final _triggersPairingWithEncryptedChar =
defaultTargetPlatform != TargetPlatform.windows;
defaultTargetPlatform != TargetPlatform.windows ||
defaultTargetPlatform != TargetPlatform.linux;
static bool hasSystemPairingApi = !kIsWeb &&
(defaultTargetPlatform == TargetPlatform.android ||
+1 -4
View File
@@ -232,14 +232,11 @@ class UniversalBle {
/// You can optionally pass a pairingCommand if you know an encrypted read or write characteristic.
/// If you do, it returns true if it can successfully execute the command after pairing.
///
/// Throws UnsupportedError on `Web/Windows`
/// On `Web/Windows` and `Web/Linux` it is known to work only for devices that require passkey pairing.
static Future<bool?> pair(
String deviceId, {
BleCommand? pairingCommand,
}) async {
if (!BleCapabilities.supportsInAppPairing) {
throw UnsupportedError("Not supported");
}
if (BleCapabilities.hasSystemPairingApi) {
return _platform.pair(deviceId);
}