BtcReconnectingConnection class Models

A self-healing RFCOMM connection that transparently reconnects when the link drops, using the exponential backoff described by its policy.

Unlike a raw BtcConnection (which is replaced on every drop), this object's input and state streams are stable: subscribe once and keep receiving data and status across reconnects. Create one via FlutterClassicBluetooth.connectWithReconnect.

final link = bluetooth.connectWithReconnect(address: 'AA:BB:CC:DD:EE:FF');
link.state.listen((s) => print('Link: ${s.name}'));
link.input.listen((bytes) => print('RX ${bytes.length} bytes'));
await link.sendString('PING\r\n'); // throws if currently reconnecting
// ...later
await link.close(); // stop reconnecting and release everything

Constructors

BtcReconnectingConnection({required String address, required Future<BtcConnection> connector(), String uuid = BtcUuid.spp, bool secure = true, BtcReconnectPolicy policy = const BtcReconnectPolicy()})
Creates a reconnecting connection driven by connector.

Properties

address → String
The remote device address this link targets.
final
attempts → int
Consecutive failed reconnect attempts since the last successful connect.
no setter
connection → BtcConnection?
The underlying live connection, or null while reconnecting/closed.
no setter
currentState → BtcReconnectState
The current link state.
no setter
hashCode → int
The hash code for this object.
no setterinherited
input → Stream<Uint8List>
Incoming bytes from the remote device, stable across reconnects.
no setter
isConnected → bool
Whether a connection is established right now.
no setter
lastError → Object?
The error from the most recent failed connect attempt, or null.
no setter
policy → BtcReconnectPolicy
The backoff/retry policy.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
secure → bool
Whether each connect attempt uses authenticated/encrypted RFCOMM.
final
state → Stream<BtcReconnectState>
High-level link-state changes (connecting → connected → reconnecting → ...).
no setter
uuid → String
The RFCOMM service UUID used for each connect attempt.
final

Methods

close() → Future<void>
Stops reconnecting, disconnects, and releases all resources.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
send(Uint8List data) → Future<void>
Sends data over the current connection.
sendAndReceive(String command, {Duration timeout = const Duration(seconds: 5), bool where(String line)?, String newline = '\r\n', Encoding encoding = utf8}) → Future<String>
Sends command over the current connection and awaits its response line.
sendLine(String text, {String newline = '\r\n', Encoding encoding = utf8}) → Future<void>
Sends text followed by newline (CRLF by default). See send.
sendString(String text, {Encoding encoding = utf8}) → Future<void>
Encodes text (UTF-8 by default) and sends it. See send.
start() → void
Begins connecting. Has no effect if already started or closed.
toString() → String
A string representation of this object.
inherited
waitConnected({Duration? timeout}) → Future<void>
Waits until the link is connected, then returns.

Operators

operator ==(Object other) → bool
The equality operator.
inherited