11import 'dart:async' ;
2- import 'dart:io' ;
32
43import 'package:flutter/foundation.dart' ;
54import 'package:flutter/material.dart' ;
@@ -12,6 +11,9 @@ import 'types/barcode_format.dart';
1211import 'types/camera.dart' ;
1312import 'types/camera_exception.dart' ;
1413import 'types/features.dart' ;
14+ import 'web/flutter_qr_stub.dart'
15+ // ignore: uri_does_not_exist
16+ if (dart.library.html) 'web/flutter_qr_web.dart' ;
1517
1618typedef QRViewCreatedCallback = void Function (QRViewController );
1719typedef PermissionSetCallback = void Function (QRViewController , bool );
@@ -111,28 +113,35 @@ class _QRViewState extends State<QRView> {
111113
112114 Widget _getPlatformQrView () {
113115 Widget _platformQrView;
114- switch (defaultTargetPlatform) {
115- case TargetPlatform .android:
116- _platformQrView = AndroidView (
117- viewType: 'net.touchcapture.qr.flutterqr/qrview' ,
118- onPlatformViewCreated: _onPlatformViewCreated,
119- creationParams:
120- _QrCameraSettings (cameraFacing: widget.cameraFacing).toMap (),
121- creationParamsCodec: StandardMessageCodec (),
122- );
123- break ;
124- case TargetPlatform .iOS:
125- _platformQrView = UiKitView (
126- viewType: 'net.touchcapture.qr.flutterqr/qrview' ,
127- onPlatformViewCreated: _onPlatformViewCreated,
128- creationParams:
129- _QrCameraSettings (cameraFacing: widget.cameraFacing).toMap (),
130- creationParamsCodec: StandardMessageCodec (),
131- );
132- break ;
133- default :
134- throw UnsupportedError (
135- "Trying to use the default qrview implementation for $defaultTargetPlatform but there isn't a default one" );
116+ if (kIsWeb) {
117+ _platformQrView = createWebQrView (
118+ onPlatformViewCreated: widget.onQRViewCreated,
119+ cameraFacing: widget.cameraFacing,
120+ );
121+ } else {
122+ switch (defaultTargetPlatform) {
123+ case TargetPlatform .android:
124+ _platformQrView = AndroidView (
125+ viewType: 'net.touchcapture.qr.flutterqr/qrview' ,
126+ onPlatformViewCreated: _onPlatformViewCreated,
127+ creationParams:
128+ _QrCameraSettings (cameraFacing: widget.cameraFacing).toMap (),
129+ creationParamsCodec: StandardMessageCodec (),
130+ );
131+ break ;
132+ case TargetPlatform .iOS:
133+ _platformQrView = UiKitView (
134+ viewType: 'net.touchcapture.qr.flutterqr/qrview' ,
135+ onPlatformViewCreated: _onPlatformViewCreated,
136+ creationParams:
137+ _QrCameraSettings (cameraFacing: widget.cameraFacing).toMap (),
138+ creationParamsCodec: StandardMessageCodec (),
139+ );
140+ break ;
141+ default :
142+ throw UnsupportedError (
143+ "Trying to use the default qrview implementation for $defaultTargetPlatform but there isn't a default one" );
144+ }
136145 }
137146 return _platformQrView;
138147 }
@@ -309,7 +318,7 @@ class QRViewController {
309318
310319 /// Stops the camera and disposes the barcode stream.
311320 void dispose () {
312- if (Platform .isIOS ) stopCamera ();
321+ if (defaultTargetPlatform == TargetPlatform .iOS ) stopCamera ();
313322 _scanUpdateController.close ();
314323 }
315324
0 commit comments