disconnect method

Future<bool> disconnect()

Disconnects the controller from the connected device. Returns true if the device is disconnected successfully, false otherwise.

Throws BITalinoException(BITalinoErrorType.TIMEOUT) if the timeout limit is reached. Throws BITalinoException(BITalinoErrorType.BT_DEVICE_NOT_CONNECTED) if a device is not connected. Throws BITalinoException(BITalinoErrorType.CUSTOM) if a native exception was raised.

Implementation

Future<bool> disconnect() async {
  if (!connected)
    throw BITalinoException(BITalinoErrorType.BT_DEVICE_NOT_CONNECTED);

  if (recording) await stop();
  try {
    bool disconnected =
        await _channel.invokeMethod("disconnect").timeout(timeout);
    if (disconnected) _disconnectVars();
    return disconnected;
  } on TimeoutException {
    throw BITalinoException(BITalinoErrorType.TIMEOUT);
  } catch (e) {
    throw BITalinoException(BITalinoErrorType.CUSTOM, e.toString());
  }
}