Skip to content

Commit

Permalink
scanning the QR code now replaces the key
Browse files Browse the repository at this point in the history
  • Loading branch information
MoazSalem committed Jul 8, 2023
1 parent 878375c commit 44d7ff3
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 8 deletions.
4 changes: 3 additions & 1 deletion assets/translations/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
"Share": "المشاركة",
"Share QR": "مشاركة المفتاح بستخدام الQR Code ",
"Scan QR": "مسح الQR Code",
"Select Device": "اختر الجهاز"
"Select Device": "اختر الجهاز",
"Warning": "تحذير",
"T5": "تم استلام المفتاح, سيتم استبدال المفتاح الحالي, هل انت متأكد؟"
}
4 changes: 3 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
"Share": "Share",
"Share QR": "Share Key Using QR",
"Scan QR": "Scan QR Code",
"Select Device": "Select Device"
"Select Device": "Select Device",
"Warning": "Warning",
"T5": "Key received from QR code, This will replace your current key, Are you sure you want to continue?"
}
22 changes: 22 additions & 0 deletions lib/Bloc/ble_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,28 @@ class BleBloc extends Bloc<BleEvent, BleState> {
return iv;
}

// this function is called in the scan qr code page
replaceKeys({required String id, required String key, required String vector}) {
String keysString = "";
String vectorsString = "";
// replace the old key and vector with the new one
// if the device is not in the list, this will add it
keys[id] = encrypt.Key.fromBase64(key);
ivs[id] = encrypt.IV.fromBase64(vector);
// recreate the stored string
for (int i = 0; i < keys.length; i++) {
keysString += "${keys.entries.elementAt(i).key}||${keys.entries.elementAt(i).value.base64}";
vectorsString += "${ivs.entries.elementAt(i).key}||${ivs.entries.elementAt(i).value.base64}";
if (i < keys.length - 1) {
keysString += ",";
vectorsString += ",";
}
}
// store the new string
box.put("Keys", keysString);
box.put("Vectors", vectorsString);
}

// Unlock or close car doors
controlDoors(BleDevice device) async {
if (finalDevicesAuthStates[device.id] == "authorized") {
Expand Down
55 changes: 50 additions & 5 deletions lib/Screens/qr_scan_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:blue/Screens/setter_page.dart';
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:easy_localization/easy_localization.dart';

class ScanQrPage extends StatelessWidget {
const ScanQrPage({super.key});
Expand All @@ -15,14 +17,57 @@ class ScanQrPage extends StatelessWidget {
// to prevent multiple scans
if (!foundQR && capture.barcodes[0].rawValue.toString().split('|||').length == 2) {
foundQR = true;
print("id:${capture.barcodes[0].rawValue.toString().split('|||')[0].split('||')[0]}");
print("key:${capture.barcodes[0].rawValue.toString().split('|||')[0].split('||')[1]}");
print("iv:${capture.barcodes[0].rawValue.toString().split('|||')[1]}");
// Navigator.of(context).pushReplacement(MaterialPageRoute(
// builder: (context) => tempPage(text: capture.barcodes[0].rawValue.toString())));
showAlertDialog(context, capture.barcodes[0].rawValue!);
}
},
),
);
}
}

showAlertDialog(BuildContext context, String barCodeValue) {
// set up the buttons
Widget cancelButton = TextButton(
child: const Text("Cancel"),
onPressed: () {
// close alert dialog
Navigator.of(context).pop();
// close qr scan page
Navigator.of(context).pop();
},
);
Widget continueButton = TextButton(
child: const Text("Continue"),
onPressed: () {
// replace key and iv
B.replaceKeys(
id: barCodeValue.toString().split('|||')[0].split('||')[0],
key: barCodeValue.toString().split('|||')[0].split('||')[1],
vector: barCodeValue.toString().split('|||')[1]);
// close alert dialog
Navigator.of(context).pop();
// close qr scan page
Navigator.of(context).pop();
// close share page
Navigator.of(context).pop();
},
);

// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: const Text("Warning").tr(),
content: const Text("T5").tr(),
actions: [
cancelButton,
continueButton,
],
);

// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.1.6
version: 1.1.7

environment:
sdk: '>=2.19.1 <3.0.0'
Expand Down

0 comments on commit 44d7ff3

Please sign in to comment.