Skip to content

Commit

Permalink
new package works great
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Oct 20, 2023
1 parent 5036335 commit 9465990
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -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<QrCameraState>();
QRScannerWidget({super.key});
class QRScannerWidget extends StatefulWidget {
// final _key = GlobalKey<QrCameraState>();
const QRScannerWidget({super.key});

@override
State<QRScannerWidget> createState() => _QRScannerWidgetState();
}

class _QRScannerWidgetState extends State<QRScannerWidget> {
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<Barcode> 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(
Expand Down
24 changes: 8 additions & 16 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 9465990

Please sign in to comment.