Navaron Bracke

remove the video element from the DOM when disposing the controller

@@ -185,5 +185,22 @@ class MobileScannerWeb extends MobileScannerPlatform { @@ -185,5 +185,22 @@ class MobileScannerWeb extends MobileScannerPlatform {
185 await stop(); 185 await stop();
186 await _barcodesController.close(); 186 await _barcodesController.close();
187 await _constraintsController.close(); 187 await _constraintsController.close();
  188 +
  189 + // Finally, remove the video element from the DOM.
  190 + try {
  191 + final HTMLCollection? divChildren = _divElement?.children;
  192 +
  193 + if (divChildren != null) {
  194 + for (int i = 0; i < divChildren.length; i++) {
  195 + final Node? child = divChildren.item(i);
  196 +
  197 + if (child != null) {
  198 + _divElement?.removeChild(child);
  199 + }
  200 + }
  201 + }
  202 + } catch (_) {
  203 + // The video element was no longer a child of the container element.
  204 + }
188 } 205 }
189 } 206 }