UniversalBleServer class
A custom GATT server whose profile describes client-readable/writable fields.
Use start, stop and dispose for lifecycle; readStoredValue and updateStoredValue for storage; sendNotification for outgoing raw bytes. Use BleMessageServer instead when exchanging complete text/binary messages. One active server per platform adapter. Native resources are process-local.
- Available extensions
Constructors
- UniversalBleServer({BleProfile? profile, UniversalBleServerPlatform? platform, Duration requestTimeout = const Duration(seconds: 5)})
Properties
-
clientReads
→ Stream<
BleReadEvent> -
Successful client reads; these events do not provide the response value.
no setter
-
clientWrites
→ Stream<
BleWriteEvent> -
Accepted client writes, emitted after storage has been updated.
no setter
-
errors
→ Stream<
Object> -
no setter
-
events
→ Stream<
Map< String, Object?> > -
Read, write, subscribed, unsubscribed, connected, disconnected and error
events. Connection events are available on Android; Apple reports
subscriptions rather than physical connections.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
onRead
→ Stream<
BleReadEvent> -
Compatibility alias for clientReads, not a dynamic read callback.
no setter
-
onWrite
→ Stream<
BleWriteEvent> -
Compatibility alias for clientWrites, not a write authorization hook.
no setter
- profile → BleProfile?
-
final
- requestTimeout → Duration
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → BleServerState
-
no setter
-
stateChanges
→ Stream<
BleServerState> -
Changes to server lifecycle state. Subscribe before start.
no setter
-
states
→ Stream<
BleServerState> -
Compatibility alias for stateChanges.
no setter
Methods
-
checkSupport(
) → Future< BleCapabilities> - Checks adapter capabilities and readiness. Apple may prompt for consent.
-
dispose(
) → Future< void> - Stops the server and closes its streams permanently. Safe to call twice.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notify(
String characteristicUuid, List< int> value, {String? clientId}) → Future<void> - Compatibility alias for sendNotification.
-
readStoredValue<
T> (BleField< T> field) → T - Returns the locally stored value, without making a Bluetooth request. A field's dynamic read callback may return a different value to clients.
-
requestPermissions(
) → Future< BleCapabilities> - Requests OS permission and returns the resulting adapter readiness.
-
sendNotification(
String characteristicUuid, List< int> value, {String? clientId}) → Future<void> -
Sends bytes to subscribers without changing the stored readable value.
Omitting
clientIdtargets all subscribers; with none, nothing is sent. Never automatically retries or fragments messages. Payload must fit the target's negotiated limit; completion is not an application-level receipt. -
setValue<
T> (BleField< T> field, T value, {bool notify = false}) → Future<void> - Compatibility alias for updateStoredValue.
-
start(
) → Future< void> - Registers profile and starts advertising. Requires a stopped server.
-
startServer(
{required String serviceUuid, required List< BleCharacteristic> characteristics, String? name, bool requireAdvertisedName = false, bool allowAndroidAdapterNameChange = false}) → Future<void> - Compatibility entry point for a single service configured at startup. Prefer a constructor profile followed by start for new code.
-
startWithPermissions(
) → Future< void> -
Available on UniversalBleServer, provided by the UniversalBleServerConvenience extension
Requests OS permission, verifies readiness and begins advertising. -
stop(
) → Future< void> - Stops advertising and releases native resources. Can be started again.
-
stopServer(
) → Future< void> - Compatibility alias for stop.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateStoredValue<
T> (BleField< T> field, T value, {bool notify = false}) → Future<void> -
Replaces a field's stored value. Set
notifyto also notify subscribers. Defaults to storing only. Clients can read storage when read access is enabled and no dynamic read hook overrides it. Applies the field's codec and validation; requires start. -
valueOf<
T> (BleField< T> field) → T - Compatibility alias for readStoredValue.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited