Navaron Bracke

bump to pkg:web 0.4.2 and add workaround for JSAny implements

@@ -14,6 +14,8 @@ import 'package:mobile_scanner/src/web/zxing/result.dart'; @@ -14,6 +14,8 @@ import 'package:mobile_scanner/src/web/zxing/result.dart';
14 import 'package:mobile_scanner/src/web/zxing/zxing_browser_multi_format_reader.dart'; 14 import 'package:mobile_scanner/src/web/zxing/zxing_browser_multi_format_reader.dart';
15 import 'package:web/web.dart' as web; 15 import 'package:web/web.dart' as web;
16 16
  17 +// TODO: remove the JSAny casts once upgraded to a package:web version that restores "implements JSAny"
  18 +
17 /// A barcode reader implementation that uses the ZXing library. 19 /// A barcode reader implementation that uses the ZXing library.
18 final class ZXingBarcodeReader extends BarcodeReader { 20 final class ZXingBarcodeReader extends BarcodeReader {
19 ZXingBarcodeReader(); 21 ZXingBarcodeReader();
@@ -110,7 +112,7 @@ final class ZXingBarcodeReader extends BarcodeReader { @@ -110,7 +112,7 @@ final class ZXingBarcodeReader extends BarcodeReader {
110 Future<web.MediaStream?> _prepareMediaStream( 112 Future<web.MediaStream?> _prepareMediaStream(
111 CameraFacing cameraDirection, 113 CameraFacing cameraDirection,
112 ) async { 114 ) async {
113 - if (web.window.navigator.mediaDevices.isUndefinedOrNull) { 115 + if ((web.window.navigator.mediaDevices as JSAny?).isUndefinedOrNull) {
114 return null; 116 return null;
115 } 117 }
116 118
@@ -119,7 +121,7 @@ final class ZXingBarcodeReader extends BarcodeReader { @@ -119,7 +121,7 @@ final class ZXingBarcodeReader extends BarcodeReader {
119 121
120 final web.MediaStreamConstraints constraints; 122 final web.MediaStreamConstraints constraints;
121 123
122 - if (capabilities.isUndefinedOrNull || !capabilities.facingMode) { 124 + if ((capabilities as JSAny).isUndefinedOrNull || !capabilities.facingMode) {
123 constraints = web.MediaStreamConstraints(video: true.toJS); 125 constraints = web.MediaStreamConstraints(video: true.toJS);
124 } else { 126 } else {
125 final String facingMode = switch (cameraDirection) { 127 final String facingMode = switch (cameraDirection) {
@@ -130,7 +132,7 @@ final class ZXingBarcodeReader extends BarcodeReader { @@ -130,7 +132,7 @@ final class ZXingBarcodeReader extends BarcodeReader {
130 constraints = web.MediaStreamConstraints( 132 constraints = web.MediaStreamConstraints(
131 video: web.MediaTrackConstraintSet( 133 video: web.MediaTrackConstraintSet(
132 facingMode: facingMode.toJS, 134 facingMode: facingMode.toJS,
133 - ), 135 + ) as JSAny,
134 ); 136 );
135 } 137 }
136 138
@@ -159,8 +161,11 @@ final class ZXingBarcodeReader extends BarcodeReader { @@ -159,8 +161,11 @@ final class ZXingBarcodeReader extends BarcodeReader {
159 final web.MediaStream? stream = await _prepareMediaStream(cameraDirection); 161 final web.MediaStream? stream = await _prepareMediaStream(cameraDirection);
160 162
161 if (stream != null) { 163 if (stream != null) {
162 - final JSPromise? result = _reader?.attachStreamToVideo  
163 - .callAsFunction(null, stream, videoElement) as JSPromise?; 164 + final JSPromise? result = _reader?.attachStreamToVideo.callAsFunction(
  165 + null,
  166 + stream as JSAny,
  167 + videoElement as JSAny,
  168 + ) as JSPromise?;
164 169
165 await result?.toDart; 170 await result?.toDart;
166 171
@@ -180,7 +185,7 @@ final class ZXingBarcodeReader extends BarcodeReader { @@ -180,7 +185,7 @@ final class ZXingBarcodeReader extends BarcodeReader {
180 controller.onListen = () { 185 controller.onListen = () {
181 _reader?.decodeContinuously.callAsFunction( 186 _reader?.decodeContinuously.callAsFunction(
182 null, 187 null,
183 - _reader?.videoElement, 188 + _reader?.videoElement as JSAny?,
184 (Result? result, JSAny? error) { 189 (Result? result, JSAny? error) {
185 if (!controller.isClosed && result != null) { 190 if (!controller.isClosed && result != null) {
186 controller.add( 191 controller.add(
@@ -25,7 +25,7 @@ dependencies: @@ -25,7 +25,7 @@ dependencies:
25 flutter_web_plugins: 25 flutter_web_plugins:
26 sdk: flutter 26 sdk: flutter
27 plugin_platform_interface: ^2.0.2 27 plugin_platform_interface: ^2.0.2
28 - web: ^0.3.0 28 + web: ^0.4.2
29 29
30 dev_dependencies: 30 dev_dependencies:
31 flutter_test: 31 flutter_test: