@@ -8,6 +8,8 @@ import 'package:mobile_scanner/mobile_scanner.dart';
8
8
9
9
import 'package:ehrenamtskarte/l10n/translations.g.dart' ;
10
10
11
+ import 'package:ehrenamtskarte/util/android_utils.dart' ;
12
+
11
13
typedef OnCodeScannedCallback = Future <void > Function (Uint8List code);
12
14
13
15
class QrCodeScanner extends StatefulWidget {
@@ -20,12 +22,29 @@ class QrCodeScanner extends StatefulWidget {
20
22
}
21
23
22
24
class _QRViewState extends State <QrCodeScanner > {
25
+ bool _hasCameraIssues = false ;
26
+
27
+ @override
28
+ void initState () {
29
+ super .initState ();
30
+ // Workaround for https://github.com/juliansteenbakker/mobile_scanner/issues/698
31
+ // Check once the qr code scanner was initialized if the device has camera issues
32
+ // Depending on that set a controller with predefined camera solution to fix that qr code reading issues
33
+ WidgetsBinding .instance.addPostFrameCallback ((_) async {
34
+ setState (() async {
35
+ _hasCameraIssues = await isDeviceWithCameraIssues ();
36
+ });
37
+ });
38
+ }
39
+
23
40
final MobileScannerController _controller = MobileScannerController (
24
- torchEnabled: false ,
25
- detectionSpeed: DetectionSpeed .normal,
26
- formats: [BarcodeFormat .qrCode],
27
- returnImage: false ,
28
- );
41
+ torchEnabled: false , detectionSpeed: DetectionSpeed .normal, formats: [BarcodeFormat .qrCode], returnImage: false );
42
+ final MobileScannerController _controllerCameraResolution = MobileScannerController (
43
+ torchEnabled: false ,
44
+ detectionSpeed: DetectionSpeed .normal,
45
+ formats: [BarcodeFormat .qrCode],
46
+ returnImage: false ,
47
+ cameraResolution: const Size (640 , 480 ));
29
48
final GlobalKey qrKey = GlobalKey (debugLabel: 'QR' );
30
49
31
50
// Determines whether a code is currently processed by the onCodeScanned callback
@@ -37,7 +56,7 @@ class _QRViewState extends State<QrCodeScanner> {
37
56
@override
38
57
Widget build (BuildContext context) {
39
58
final t = context.t;
40
- final controller = _controller;
59
+ final controller = _hasCameraIssues ? _controllerCameraResolution : _controller;
41
60
return Stack (
42
61
children: [
43
62
Column (
0 commit comments