Skip to content

Commit

Permalink
fix: add disable qr challenge functionality (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurgit45 authored Mar 10, 2024
1 parent b7fef55 commit a75078e
Showing 1 changed file with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class AddOrUpdateAlarmController extends GetxController {
facing: CameraFacing.back,
torchEnabled: false,
);
final qrValue = ''.obs;
final qrValue = ''.obs; // qrvalue stored in alarm
final detectedQrValue = ''.obs; // QR value detected by camera
final isQrEnabled = false.obs;

final mathsSliderValue = 0.0.obs;
Expand Down Expand Up @@ -410,7 +411,7 @@ class AddOrUpdateAlarmController extends GetxController {
}

showQRDialog() {
restartQRCodeController();
restartQRCodeController(false);
Get.defaultDialog(
titlePadding: const EdgeInsets.symmetric(vertical: 20),
backgroundColor: themeController.isLightMode.value
Expand All @@ -421,7 +422,7 @@ class AddOrUpdateAlarmController extends GetxController {
content: Obx(
() => Column(
children: [
isQrEnabled.value == false
detectedQrValue.value.isEmpty
? SizedBox(
height: 300,
width: 300,
Expand All @@ -431,18 +432,17 @@ class AddOrUpdateAlarmController extends GetxController {
onDetect: (capture) {
final List<Barcode> barcodes = capture.barcodes;
for (final barcode in barcodes) {
qrValue.value = barcode.rawValue.toString();
detectedQrValue.value = barcode.rawValue.toString();
debugPrint(barcode.rawValue.toString());
isQrEnabled.value = true;
}
},
),
)
: Padding(
padding: const EdgeInsets.only(bottom: 15.0),
child: Text(qrValue.value),
child: Text(detectedQrValue.value),
),
isQrEnabled.value == true
(detectedQrValue.value.isNotEmpty)
? Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expand All @@ -463,6 +463,8 @@ class AddOrUpdateAlarmController extends GetxController {
),
),
onPressed: () {
qrValue.value = detectedQrValue.value;
isQrEnabled.value = true;
Get.back();
},
),
Expand All @@ -484,10 +486,32 @@ class AddOrUpdateAlarmController extends GetxController {
),
onPressed: () async {
qrController.dispose();
restartQRCodeController();
isQrEnabled.value = false;
restartQRCodeController(true);
},
),
if (isQrEnabled.value)
TextButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(kprimaryColor),
),
child: Text(
'Disable',
style: Theme.of(Get.context!)
.textTheme
.displaySmall!
.copyWith(
color: themeController.isLightMode.value
? kLightPrimaryTextColor
: ksecondaryTextColor,
),
),
onPressed: () {
isQrEnabled.value = false;
qrValue.value = '';
Get.back();
},
),
],
)
: const SizedBox(),
Expand Down Expand Up @@ -576,14 +600,15 @@ class AddOrUpdateAlarmController extends GetxController {
}
}

restartQRCodeController() async {
restartQRCodeController(bool retake) async {
// Camera permission already granted, proceed with QR code scanning
qrController = MobileScannerController(
autoStart: true,
detectionSpeed: DetectionSpeed.noDuplicates,
facing: CameraFacing.back,
torchEnabled: false,
);
detectedQrValue.value = retake ? '' : qrValue.value;
}

updateAlarm(AlarmModel alarmData) async {
Expand Down Expand Up @@ -719,6 +744,7 @@ class AddOrUpdateAlarmController extends GetxController {

isQrEnabled.value = alarmRecord!.isQrEnabled;
qrValue.value = alarmRecord!.qrValue;
detectedQrValue.value = alarmRecord!.qrValue;

alarmID = alarmRecord!.alarmID;
ownerId = alarmRecord!.ownerId;
Expand Down

0 comments on commit a75078e

Please sign in to comment.