diff --git a/README.md b/README.md
index 2713f6e..cd02afe 100644
--- a/README.md
+++ b/README.md
@@ -132,6 +132,20 @@ In order to use this plugin, add the following to your Info.plist file:
This app needs camera access to scan QR codes
```
+## Web Integration
+
+Add this to `web/index.html`:
+
+```html
+
+```
+
+Please note: on web, only QR codes are supported. Other barcodes and 2D codes cannot be scanned.
+
+Web support is in very earlt stage. Features such as flash, pause or resume are not implemented. Moreover, the camera
+preview does not respect the surrounding constraints. This is not at last due to Flutter's early state of platform views
+on web.
+
## Flip Camera (Back/Front)
The default camera is the back camera.
```dart
diff --git a/lib/src/qr_code_scanner.dart b/lib/src/qr_code_scanner.dart
index 03a1a39..96fef34 100644
--- a/lib/src/qr_code_scanner.dart
+++ b/lib/src/qr_code_scanner.dart
@@ -1,5 +1,4 @@
import 'dart:async';
-import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@@ -12,6 +11,9 @@ import 'types/barcode_format.dart';
import 'types/camera.dart';
import 'types/camera_exception.dart';
import 'types/features.dart';
+import 'web/flutter_qr_stub.dart'
+// ignore: uri_does_not_exist
+ if (dart.library.html) 'web/flutter_qr_web.dart';
typedef QRViewCreatedCallback = void Function(QRViewController);
typedef PermissionSetCallback = void Function(QRViewController, bool);
@@ -111,28 +113,35 @@ class _QRViewState extends State {
Widget _getPlatformQrView() {
Widget _platformQrView;
- switch (defaultTargetPlatform) {
- case TargetPlatform.android:
- _platformQrView = AndroidView(
- viewType: 'net.touchcapture.qr.flutterqr/qrview',
- onPlatformViewCreated: _onPlatformViewCreated,
- creationParams:
- _QrCameraSettings(cameraFacing: widget.cameraFacing).toMap(),
- creationParamsCodec: StandardMessageCodec(),
- );
- break;
- case TargetPlatform.iOS:
- _platformQrView = UiKitView(
- viewType: 'net.touchcapture.qr.flutterqr/qrview',
- onPlatformViewCreated: _onPlatformViewCreated,
- creationParams:
- _QrCameraSettings(cameraFacing: widget.cameraFacing).toMap(),
- creationParamsCodec: StandardMessageCodec(),
- );
- break;
- default:
- throw UnsupportedError(
- "Trying to use the default qrview implementation for $defaultTargetPlatform but there isn't a default one");
+ if (kIsWeb) {
+ _platformQrView = createWebQrView(
+ onPlatformViewCreated: widget.onQRViewCreated,
+ cameraFacing: widget.cameraFacing,
+ );
+ } else {
+ switch (defaultTargetPlatform) {
+ case TargetPlatform.android:
+ _platformQrView = AndroidView(
+ viewType: 'net.touchcapture.qr.flutterqr/qrview',
+ onPlatformViewCreated: _onPlatformViewCreated,
+ creationParams:
+ _QrCameraSettings(cameraFacing: widget.cameraFacing).toMap(),
+ creationParamsCodec: StandardMessageCodec(),
+ );
+ break;
+ case TargetPlatform.iOS:
+ _platformQrView = UiKitView(
+ viewType: 'net.touchcapture.qr.flutterqr/qrview',
+ onPlatformViewCreated: _onPlatformViewCreated,
+ creationParams:
+ _QrCameraSettings(cameraFacing: widget.cameraFacing).toMap(),
+ creationParamsCodec: StandardMessageCodec(),
+ );
+ break;
+ default:
+ throw UnsupportedError(
+ "Trying to use the default qrview implementation for $defaultTargetPlatform but there isn't a default one");
+ }
}
return _platformQrView;
}
@@ -313,7 +322,7 @@ class QRViewController {
/// Stops the camera and disposes the barcode stream.
void dispose() {
- if (Platform.isIOS) stopCamera();
+ if (defaultTargetPlatform == TargetPlatform.iOS) stopCamera();
_scanUpdateController.close();
}
diff --git a/pubspec.yaml b/pubspec.yaml
index 722fd49..3b65d58 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -11,6 +11,8 @@ environment:
dependencies:
flutter:
sdk: flutter
+ flutter_web_plugins:
+ sdk: flutter
dev_dependencies:
pedantic: ^1.11.0
@@ -23,3 +25,7 @@ flutter:
pluginClass: FlutterQrPlugin
ios:
pluginClass: FlutterQrPlugin
+
+# web:
+# pluginClass: FlutterQrPlugin
+# fileName: flutter_qr_web.dart