From 9465990d5e4bfcef40e686dab9f7b155151824fb Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Fri, 20 Oct 2023 16:20:42 +0200 Subject: [PATCH] new package works great --- .../qr_scanner_widget.dart | 62 ++++++++----------- pubspec.lock | 24 +++---- pubspec.yaml | 4 +- 3 files changed, 35 insertions(+), 55 deletions(-) diff --git a/lib/views/qr_scanner_view/qr_scanner_view_widgets/qr_scanner_widget.dart b/lib/views/qr_scanner_view/qr_scanner_view_widgets/qr_scanner_widget.dart index fd6d73fa6..2d5f141ef 100644 --- a/lib/views/qr_scanner_view/qr_scanner_view_widgets/qr_scanner_widget.dart +++ b/lib/views/qr_scanner_view/qr_scanner_view_widgets/qr_scanner_widget.dart @@ -1,51 +1,39 @@ import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:qr_mobile_vision/qr_camera.dart'; +import 'package:mobile_scanner/mobile_scanner.dart'; -import '../../../utils/logger.dart'; -import '../../../utils/view_utils.dart'; import 'qr_code_scanner_overlay.dart'; -class QRScannerWidget extends StatelessWidget { - final _key = GlobalKey(); - QRScannerWidget({super.key}); +class QRScannerWidget extends StatefulWidget { + // final _key = GlobalKey(); + const QRScannerWidget({super.key}); + @override + State createState() => _QRScannerWidgetState(); +} + +class _QRScannerWidgetState extends State { + bool alreadyDetected = false; @override Widget build(BuildContext context) => SizedBox.expand( child: Stack( alignment: Alignment.center, children: [ - QrCamera( - fit: BoxFit.cover, - key: _key, - formats: const [BarcodeFormats.QR_CODE], - // Ignore other codes than qr codes - onError: (context, e) { - WidgetsBinding.instance.addPostFrameCallback((_) { - if (e is PlatformException && e.message == 'noPermission') { - Logger.warning( - 'QRScannerView: Camera permission not granted.', - name: 'QRScannerView#build#onError', - error: e, - stackTrace: StackTrace.current, - ); - showMessage(message: 'Please grant camera permission to use the QR scanner.'); - } - // Navigator.pop(context, null); - // _key.currentState!.stop(); + MobileScanner( + fit: BoxFit.contain, + controller: MobileScannerController( + // facing: CameraFacing.back, + // torchEnabled: false, + returnImage: false, + ), + onDetect: (capture) { + if (alreadyDetected) return; + alreadyDetected = true; + final List barcodes = capture.barcodes; + for (final barcode in barcodes) { + debugPrint('Barcode found! ${barcode.rawValue}'); + } - // Method must return a widget, so return one that does not display anything. - }); - return const SizedBox(); - }, - // We have nothing to display in these cases, overwrite default - // behaviour with 'non-visible' content. - child: const SizedBox(), - notStartedBuilder: (_) => const SizedBox(), - offscreenBuilder: (_) => const SizedBox(), - qrCodeCallback: (code) { - Navigator.pop(context, code); - _key.currentState!.stop(); + Navigator.pop(context, barcodes.first.rawValue); }, ), Container( diff --git a/pubspec.lock b/pubspec.lock index 177521dcf..e3aa64e5a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -788,6 +788,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.4" + mobile_scanner: + dependency: "direct main" + description: + name: mobile_scanner + sha256: "2fbc3914fe625e196c64ea8ffc4084cd36781d2be276d4d5923b11af3b5d44ff" + url: "https://pub.dev" + source: hosted + version: "3.4.1" mockito: dependency: "direct dev" description: @@ -804,14 +812,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.0" - native_device_orientation: - dependency: transitive - description: - name: native_device_orientation - sha256: "744a03030fad5a332a54833cd34f1e2ee51ae9acf477b4ef85bacc8823af9937" - url: "https://pub.dev" - source: hosted - version: "1.2.1" nm: dependency: transitive description: @@ -1027,14 +1027,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.3" - qr_mobile_vision: - dependency: "direct main" - description: - name: qr_mobile_vision - sha256: bd17a9eb6227a0072fc1a9b0eaf8fc791560188417740f254fee0b9335239b1d - url: "https://pub.dev" - source: hosted - version: "4.1.3" riverpod: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9241fd280..ae8541cb7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ publish_to: none # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 4.2.0+402020 # TODO Set the right version number +version: 4.2.1+402101 # TODO Set the right version number # version: major.minor.build + 2x major|2x minor|3x build # version: version number + build number (optional) # android: build-name + versionCode @@ -34,7 +34,6 @@ dependencies: hex: ^0.2.0 base32: ^2.1.1 otp: ^3.0.1 - qr_mobile_vision: ^4.1.3 flutter_secure_storage: ^9.0.0 flutter_slidable: ^3.0.0 package_info_plus: ^4.0.2 @@ -76,6 +75,7 @@ dependencies: device_info_plus: ^9.0.3 json_annotation: ^4.8.1 equatable: ^2.0.5 + mobile_scanner: ^3.4.1 dev_dependencies: flutter_driver: