Sfoglia il codice sorgente

Added web support

flutter-beta
TheOneWithTheBraid 5 anni fa
parent
commit
0b68ed68ac
3 ha cambiato i file con 53 aggiunte e 24 eliminazioni
  1. +14
    -0
      README.md
  2. +33
    -24
      lib/src/qr_code_scanner.dart
  3. +6
    -0
      pubspec.yaml

+ 14
- 0
README.md Vedi File

@@ -132,6 +132,20 @@ In order to use this plugin, add the following to your Info.plist file:
<string>This app needs camera access to scan QR codes</string>
```

## Web Integration

Add this to `web/index.html`:

```html
<script src="https://cdn.jsdelivr.net/npm/jsqr@1.3.1/dist/jsQR.min.js"></script>
```

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


+ 33
- 24
lib/src/qr_code_scanner.dart Vedi File

@@ -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<QRView> {

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();
}



+ 6
- 0
pubspec.yaml Vedi File

@@ -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

Caricamento…
Annulla
Salva