Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

655: replace qr_code_scanner with mobile_scanner #679

Merged
merged 7 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"args": [
"flutter",
"run",
"--dart-define=environment=local"
"--dart-define=environment=local",
"--flavor=Bayern"
],
"problemMatcher": [
"$gradle"
Expand Down
2 changes: 1 addition & 1 deletion frontend/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ android {
}

defaultConfig {
minSdkVersion 20
minSdkVersion 21
targetSdkVersion 33
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
Expand Down
100 changes: 90 additions & 10 deletions frontend/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,77 @@ PODS:
- Flutter
- geolocator_apple (1.2.0):
- Flutter
- GoogleDataTransport (9.2.0):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
- GoogleMLKit/BarcodeScanning (3.2.0):
- GoogleMLKit/MLKitCore
- MLKitBarcodeScanning (~> 2.2.0)
- GoogleMLKit/MLKitCore (3.2.0):
- MLKitCommon (~> 8.0.0)
- GoogleToolboxForMac/DebugUtils (2.3.2):
- GoogleToolboxForMac/Defines (= 2.3.2)
- GoogleToolboxForMac/Defines (2.3.2)
- GoogleToolboxForMac/Logger (2.3.2):
- GoogleToolboxForMac/Defines (= 2.3.2)
- "GoogleToolboxForMac/NSData+zlib (2.3.2)":
- GoogleToolboxForMac/Defines (= 2.3.2)
- "GoogleToolboxForMac/NSDictionary+URLArguments (2.3.2)":
- GoogleToolboxForMac/DebugUtils (= 2.3.2)
- GoogleToolboxForMac/Defines (= 2.3.2)
- "GoogleToolboxForMac/NSString+URLArguments (= 2.3.2)"
- "GoogleToolboxForMac/NSString+URLArguments (2.3.2)"
- GoogleUtilities/Environment (7.7.0):
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Logger (7.7.0):
- GoogleUtilities/Environment
- GoogleUtilities/UserDefaults (7.7.0):
- GoogleUtilities/Logger
- GoogleUtilitiesComponents (1.1.0):
- GoogleUtilities/Logger
- GTMSessionFetcher/Core (1.7.2)
- MapLibre (5.12.2)
- maplibre_gl (0.0.1):
- Flutter
- MapLibre (~> 5.12.2)
- MapLibreAnnotationExtension (~> 0.0.1-beta.2)
- MapLibreAnnotationExtension (0.0.1-beta.2):
- MapLibre (~> 5.12.0)
- MTBBarcodeScanner (5.0.11)
- MLImage (1.0.0-beta3)
- MLKitBarcodeScanning (2.2.0):
- MLKitCommon (~> 8.0)
- MLKitVision (~> 4.2)
- MLKitCommon (8.0.0):
- GoogleDataTransport (~> 9.0)
- GoogleToolboxForMac/Logger (~> 2.1)
- "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
- "GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)"
- GoogleUtilities/UserDefaults (~> 7.0)
- GoogleUtilitiesComponents (~> 1.0)
- GTMSessionFetcher/Core (~> 1.1)
- Protobuf (~> 3.12)
- MLKitVision (4.2.0):
- GoogleToolboxForMac/Logger (~> 2.1)
- "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
- GTMSessionFetcher/Core (~> 1.1)
- MLImage (= 1.0.0-beta3)
- MLKitCommon (~> 8.0)
- Protobuf (~> 3.12)
- mobile_scanner (0.0.1):
- Flutter
- GoogleMLKit/BarcodeScanning (~> 3.2.0)
- nanopb (2.30909.0):
- nanopb/decode (= 2.30909.0)
- nanopb/encode (= 2.30909.0)
- nanopb/decode (2.30909.0)
- nanopb/encode (2.30909.0)
- package_info_plus (0.4.5):
- Flutter
- path_provider_ios (0.0.1):
- Flutter
- qr_code_scanner (0.2.0):
- Flutter
- MTBBarcodeScanner
- PromisesObjC (2.1.1)
- Protobuf (3.21.12)
- ReachabilitySwift (5.0.0)
- shared_preferences_ios (0.0.1):
- Flutter
Expand All @@ -36,9 +92,9 @@ DEPENDENCIES:
- MapLibre
- maplibre_gl (from `.symlinks/plugins/maplibre_gl/ios`)
- MapLibreAnnotationExtension
- mobile_scanner (from `.symlinks/plugins/mobile_scanner/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- qr_code_scanner (from `.symlinks/plugins/qr_code_scanner/ios`)
- shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)

Expand All @@ -47,7 +103,19 @@ SPEC REPOS:
- MapLibre
- MapLibreAnnotationExtension
trunk:
- MTBBarcodeScanner
- GoogleDataTransport
- GoogleMLKit
- GoogleToolboxForMac
- GoogleUtilities
- GoogleUtilitiesComponents
- GTMSessionFetcher
- MLImage
- MLKitBarcodeScanning
- MLKitCommon
- MLKitVision
- nanopb
- PromisesObjC
- Protobuf
- ReachabilitySwift

EXTERNAL SOURCES:
Expand All @@ -61,12 +129,12 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/geolocator_apple/ios"
maplibre_gl:
:path: ".symlinks/plugins/maplibre_gl/ios"
mobile_scanner:
:path: ".symlinks/plugins/mobile_scanner/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_ios:
:path: ".symlinks/plugins/path_provider_ios/ios"
qr_code_scanner:
:path: ".symlinks/plugins/qr_code_scanner/ios"
shared_preferences_ios:
:path: ".symlinks/plugins/shared_preferences_ios/ios"
url_launcher_ios:
Expand All @@ -77,13 +145,25 @@ SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_secure_storage: 7953c38a04c3fdbb00571bcd87d8e3b5ceb9daec
geolocator_apple: cc556e6844d508c95df1e87e3ea6fa4e58c50401
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
GoogleMLKit: 0017a6a8372e1a182139b9def4d89be5d87ca5a7
GoogleToolboxForMac: 8bef7c7c5cf7291c687cf5354f39f9db6399ad34
GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1
GoogleUtilitiesComponents: 679b2c881db3b615a2777504623df6122dd20afe
GTMSessionFetcher: 5595ec75acf5be50814f81e9189490412bad82ba
MapLibre: 5aa820115d91293a4d09e681e7470f88bd34b672
maplibre_gl: 2a0ce99f40b3a133b0e8b40b5ef37e0562165399
MapLibreAnnotationExtension: bc7f1041206218d7d24ba0908e3145cd54b86664
MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb
MLImage: 489dfec109f21da8621b28d476401aaf7a0d4ff4
MLKitBarcodeScanning: d92fe1911001ec36870162c5a0eb206f612b7169
MLKitCommon: f6da6c5659618c070b50a80db01248ebe2964175
MLKitVision: 96c96571190b7f63eddf4a12068ce8a8689e0d2c
mobile_scanner: 0cf06f3d5224576aa24ade02a6f73d8b2551c7bf
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
qr_code_scanner: bb67d64904c3b9658ada8c402e8b4d406d5d796e
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
Protobuf: 120350fc38646e2dedc26f49ecba778184ea1de2
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
Expand Down
22 changes: 9 additions & 13 deletions frontend/lib/identification/identification_qr_scanner_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ class IdentificationQrScannerPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Expanded(
child: Column(
children: [
const NavigationBar(
title: "Karte hinzufügen",
),
Expanded(
child: QrCodeScannerPage(
onCodeScanned: (code) async => _onCodeScanned(context, code),
),
)
],
),
return Column(
children: [
const NavigationBar(
title: "Karte hinzufügen",
),
QrCodeScannerPage(
onCodeScanned: (code) async => _onCodeScanned(context, code),
),
],
);
}

Expand Down
90 changes: 34 additions & 56 deletions frontend/lib/qr_code_scanner/qr_code_scanner.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'dart:math';

import 'package:ehrenamtskarte/qr_code_scanner/qr_code_scanner_controls.dart';
import 'package:ehrenamtskarte/qr_code_scanner/qr_overlay_shape.dart';
import 'package:flutter/material.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:mobile_scanner/mobile_scanner.dart';

const scanDelayAfterErrorMs = 500;

Expand All @@ -18,7 +19,10 @@ class QrCodeScanner extends StatefulWidget {
}

class _QRViewState extends State<QrCodeScanner> {
QRViewController? _controller;
final MobileScannerController _controller = MobileScannerController(
torchEnabled: false,
formats: [BarcodeFormat.qrCode],
);
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
bool isProcessingCode = false;

Expand All @@ -27,37 +31,35 @@ class _QRViewState extends State<QrCodeScanner> {
final controller = _controller;
return Column(
children: <Widget>[
Expanded(
flex: 4,
child: QRView(
key: qrKey,
onQRViewCreated: _onQrViewCreated,
overlay: QrScannerOverlayShape(
borderColor: Theme.of(context).colorScheme.secondary,
borderRadius: 10,
borderLength: 30,
borderWidth: 10,
cutOutSize: _calculateScanArea(context),
Stack(
children: [
MobileScanner(
key: qrKey,
onDetect: (barcode, args) => _onCodeScanned(barcode),
allowDuplicates: false,
controller: controller,
),
),
),
if (controller != null)
Expanded(
flex: 1,
child: FittedBox(
fit: BoxFit.contain,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
margin: const EdgeInsets.all(8),
child: const Text('Halten Sie die Kamera auf den QR Code.'),
Padding(
padding: EdgeInsets.zero,
child: DecoratedBox(
decoration: ShapeDecoration(
shape: QrScannerOverlayShape(
borderRadius: 10,
borderColor: Theme.of(context).colorScheme.secondary,
borderLength: 30,
borderWidth: 10,
cutOutSize: _calculateScanArea(context),
),
QrCodeScannerControls(controller: controller)
],
),
),
),
)
Container(
margin: const EdgeInsets.all(8),
child: const Text('Halten Sie die Kamera auf den QR Code.'),
),
QrCodeScannerControls(controller: controller)
],
),
],
);
}
Expand All @@ -76,42 +78,18 @@ class _QRViewState extends State<QrCodeScanner> {
return scanArea;
}

void _onQrViewCreated(QRViewController controller) {
setState(() {
_controller = controller;
});
controller.scannedDataStream.listen(_onCodeScanned);
}

Future<void> _onCodeScanned(Barcode scanData) async {
final controller = _controller;
final code = scanData.code;
if (controller == null || code == null) {
final code = scanData.rawValue;
if (code == null) {
return;
}

// needed because this method gets called multiple times in a row after one
// qr code gets detected, therefore we need to protect it
if (isProcessingCode) {
return;
}
isProcessingCode = true;
controller.pauseCamera();

await widget.onCodeScanned(code);

// give the user time to move the camara away from the qr code
await Future.delayed(const Duration(milliseconds: scanDelayAfterErrorMs));

if (mounted) {
controller.resumeCamera();
}
isProcessingCode = false;
}

@override
void dispose() {
_controller?.dispose();
_controller.dispose();
super.dispose();
}
}
Loading