scientifichackers / flutter-rx-ble

A Flutter BLE plugin, based on RxAndroidBle and RxBluetoothKit.
GNU Lesser General Public License v3.0
35 stars 18 forks source link

Trying to connect to a turned off device #5

Closed 01xJoao closed 5 years ago

01xJoao commented 5 years ago

Since the connect method doesn't have a timeout, if I try to connect to a turned off device it keeps trying to connect without stoping.

devxpy commented 5 years ago

You can use dart's in-built timeout for streams.

final stream = RxBle.connect(deviceId, autoConnect: true).timeout(
  timeout,
  onTimeout: (sink) {
      ...
  },
);

await for (final state in stream) {
    ...
}