dispose method

Future<bool> dispose()

Disposes the controller. Must be called to avoid memory leaks. Returns true if the controller is disposed successfully, false otherwise.

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

Implementation

Future<bool> dispose() async {
  try {
    if (recording) await stop();
  } catch (e) {
    print(e.toString());
  }
  if (connected) await disconnect();
  _dataStreamSubscription?.cancel();
  _channel.setMethodCallHandler(null);
  _disconnectVars();
  try {
    bool disposed;
    if (Platform.isAndroid)
      disposed = await _channel.invokeMethod("dispose").timeout(timeout);
    else
      disposed = true;
    if (disposed) this.initialized = false;
    return disposed;
  } on TimeoutException {
    throw BITalinoException(BITalinoErrorType.TIMEOUT);
  } catch (e) {
    throw BITalinoException(BITalinoErrorType.CUSTOM, e.toString());
  }
}