dispose method

  1. @override
Future<void> dispose()
override

Dispose the controller.

Once the controller is disposed, it cannot be used anymore.

Implementation

@override
Future<void> dispose() async {
  if (_isDisposed) {
    return;
  }

  _isDisposed = true;
  _disposeListeners();
  unawaited(_barcodesController.close());
  super.dispose();

  // If another controller currently holds the platform camera session,
  // disposing the platform resources would break that controller.
  // In that case only this controller's own resources are cleaned up.
  if (_platformSessionOwner != null &&
      !identical(_platformSessionOwner, this)) {
    return;
  }

  _platformSessionOwner = null;

  await MobileScannerPlatform.instance.dispose();
}