Skip to content

Commit

Permalink
[qr-code-scanner] add functionality to check for duplicates in scanne…
Browse files Browse the repository at this point in the history
…d values

Signed-off-by: Ritesh Khadse <[email protected]>
  • Loading branch information
Ritsz123 committed Feb 21, 2024
1 parent 7a9241c commit efbf2ef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ build/
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3

# FVM Version Cache
.fvm/
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ packages:
dependency: transitive
description:
name: firebase_messaging
sha256: "199fe8186a5370d1cf5ce0819191079afc305914e8f38715f5e23943940dfe2d"
sha256: "980259425fa5e2afc03e533f33723335731d21a56fd255611083bceebf4373a8"
url: "https://pub.dev"
source: hosted
version: "14.7.9"
version: "14.7.10"
firebase_messaging_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -1380,10 +1380,10 @@ packages:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: f099b552bd331eacd69affed7ff2f23bfa6b0cb825b629edf3d844375a7501ad
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
url: "https://pub.dev"
source: hosted
version: "2.2.1"
version: "2.3.2"
url_launcher_web:
dependency: transitive
description:
Expand Down
21 changes: 20 additions & 1 deletion lib/src/widgets/qr_code_scanner/qr_code_scanner.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'dart:io';

import 'package:fa_flutter_core/fa_flutter_core.dart';
import 'package:flutter/material.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';

class QrCodeScanner extends StatefulWidget {
const QrCodeScanner({Key? key, this.validationRegex}) : super(key: key);
const QrCodeScanner({Key? key, this.validationRegex, this.scannedValues})
: super(key: key);

final String? validationRegex;
final List<String>? scannedValues;

@override
State<QrCodeScanner> createState() => _QrScannerState();
Expand Down Expand Up @@ -149,6 +152,22 @@ class _QrScannerState extends State<QrCodeScanner> {
} else {
throw Exception("Scanned data is empty");
}

//incase of unique scans.
if (checkIfListIsNotEmpty(widget.scannedValues)) {
if (widget.scannedValues!.contains(dataToReturn)) {
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
"You have already scanned this QR code.",
),
),
);
return;
}
}

Navigator.pop(context, dataToReturn);
}
}
Expand Down

0 comments on commit efbf2ef

Please sign in to comment.