Bluetooth class
The main Bluetooth class. This is the entrypoint to the library. This is where you can get your devices and go further from there.
Make sure to check isBluetoothAPISupported and getAvailability to make sure Bluetooth is actually available.
Properties
-
availabilityChanged
→ Stream<
WebBluetoothValueEvent< JSBoolean> > -
An event fired when the bluetooth adapter becomes available or unavailable.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
onAdvertisementReceived
→ Stream<
BluetoothAdvertisementReceivedEvent> -
An event fired when an advertisement packet is received.
no setter
-
onCharacteristicValueChanged
→ Stream<
Event> -
An event fired on an characteristic when the characteristic value has changed.
no setter
-
onGattServerDisconnected
→ Stream<
Event> -
An event fired when the gatt server disconnects. Either the
NativeBluetoothRemoteGATTServer.disconnect method was called. Or the
device is out of range/ turned off.
no setter
-
onServiceAdded
→ Stream<
Event> -
An event fired on a device when a service has been added.
no setter
-
onServiceChanged
→ Stream<
Event> -
An event fired on a device when a service has changed.
no setter
-
onServiceRemoved
→ Stream<
Event> -
An event fired on a device when a service has been removed.
no setter
Static Methods
-
addEventListener<
T extends JSAny?> (String type, void listener(T), [AddEventListenerOptions? options]) → JSFunction - Add a new event listener to the device.
-
getAvailability(
) → Future< bool> - Check if a bluetooth adapter is available for the browser (user agent) If no bluetooth adapters are available to the browser it will resolve into false. This may return true even if the adapter is disabled by the user.
-
getDevices(
) → Future< List< WebBluetoothDevice> > - Get a list back of already paired devices. A device becomes paired once a user clicks on it in the pair menu and the web app also connects to the device. If only a user pairs a device, but not connection attempt is made then it won't be marked as paired.
-
hasGetDevices(
) → bool - Check to see if the getDevices call is available in the current browser.
-
hasRequestLEScan(
) → bool - Check to see if the current browser has the requestLEScan method.
-
isBluetoothAPISupported(
) → bool - Check to see if the Bluetooth api is even support in the current browser.
-
onAvailabilityChanged(
) → Stream< bool> - Get a Stream for the availability of a Bluetooth adapter. If a user inserts or removes a bluetooth adapter from their devices this stream will update. It will not necessarily update if the user enables/ disables a bluetooth adapter.
-
removeEventListener(
String type, JSFunction listener, [EventListenerOptions? options]) → void - Remove an event listener that has previously been added.
-
requestDevice(
RequestOptions options) → Future< WebBluetoothDevice> - Request the use of a device from the user. Calling this will show the user a dialog in which they will be able to select a single device to pair with
-
requestLEScan(
BluetoothLEScanOptions options) → Future< BluetoothLEScan> - Request the user to start scanning for Bluetooth LE devices in the area. Not every browser supports this method yet so check it using hasRequestLEScan. However even if the browser supports it, the Future may never complete on browsers. This has been the case for Chrome on linux and windows even with the correct flag enabled. Chrome on Android does seem to work. Add a Future.timeout to combat this.