1

okay that's it bye

This commit is contained in:
Kima 2024-11-13 20:51:24 +01:00
parent 3708b917c4
commit 414755c777
3 changed files with 39 additions and 36 deletions
refilc/lib/api/providers
refilc_mobile_ui/lib/screens/settings

@ -59,8 +59,8 @@ Future<void> syncAll(BuildContext context) {
tasks = [
// refresh login
syncStatus(() async {
print(user.user?.accessTokenExpire);
print('${user.user?.accessToken ?? "no token"} - ACCESS TOKEN');
// print(user.user?.accessTokenExpire);
// print('${user.user?.accessToken ?? "no token"} - ACCESS TOKEN');
if (user.user == null) return;
if (user.user!.accessTokenExpire.isBefore(DateTime.now())) {

@ -135,6 +135,7 @@ extension SettingsLocalization on String {
"camera_perm_error":
"Camera permission is required to scan QR codes.",
"invalid_qr_code": "Invalid QR code!",
"success": "Success!",
},
"hu_hu": {
"heads_up": "Figyelem!",
@ -268,6 +269,7 @@ extension SettingsLocalization on String {
"camera_perm_error":
"A kamera engedély szükséges a QR kódok beolvasásához.",
"invalid_qr_code": "Érvénytelen QR kód!",
"success": "Siker!",
},
"de_de": {
"heads_up": "Achtung!",
@ -401,6 +403,7 @@ extension SettingsLocalization on String {
"camera_perm_error":
"Kameraberechtigung ist erforderlich, um QR-Codes zu scannen.",
"invalid_qr_code": "Ungültiger QR-Code!",
"success": "Erfolg!",
},
};

@ -20,8 +20,6 @@ class _CodeScannerScreenState extends State<CodeScannerScreen> {
QRViewController? controller;
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
// In order to get hot reload to work we need to pause the camera if the platform
// is android, or resume the camera if the platform is iOS.
@override
void reassemble() {
super.reassemble();
@ -65,38 +63,15 @@ class _CodeScannerScreenState extends State<CodeScannerScreen> {
],
),
body: _buildQrView(context),
// body: Column(
// children: <Widget>[
// Expanded(flex: 4, child: _buildQrView(context)),
// // Expanded(
// // flex: 1,
// // child: FittedBox(
// // fit: BoxFit.contain,
// // child: Column(
// // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// // children: <Widget>[
// // if (result != null)
// // Text(
// // 'Barcode Type: ${describeEnum(result!.format)} Data: ${result!.code}')
// // else
// // const Text('Scan a code'),
// // ],
// // ),
// // ),
// // )
// ],
// ),
);
}
Widget _buildQrView(BuildContext context) {
// For this example we check how width or tall the device is and change the scanArea and overlay accordingly.
var scanArea = (MediaQuery.of(context).size.width < 400 ||
MediaQuery.of(context).size.height < 400)
? 150.0
: 280.0;
// To ensure the Scanner view is properly sizes after rotation
// we need to listen for Flutter SizeChanged notification and update controller
return QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
@ -116,14 +91,13 @@ class _CodeScannerScreenState extends State<CodeScannerScreen> {
this.controller = controller;
});
controller.scannedDataStream.listen((scanData) {
controller.pauseCamera();
// controller.pauseCamera();
if (result?.code == scanData.code) return;
setState(() {
result = scanData;
});
Navigator.of(context).pop();
if (scanData.code != null) {
if (scanData.code!.startsWith('qw://')) {
// String data = scanData.code!.replaceFirst('qw://', '');
@ -131,29 +105,55 @@ class _CodeScannerScreenState extends State<CodeScannerScreen> {
// TODO: this qr shit
} else if (scanData.code!.startsWith('https://') ||
scanData.code!.startsWith('http://')) {
Uri uri = Uri.parse(scanData.code!.replaceFirst('http', 'https'));
Uri uri =
Uri.parse(scanData.code!.replaceFirst('http://', 'https://'));
// print(uri);
if (uri.host.contains('refilc.hu') ||
uri.host.contains('refilcapp.hu') ||
uri.host.contains('filc.one')) {
launchUrl(uri, mode: LaunchMode.inAppBrowserView);
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
content: Text("success".i18n,
style: const TextStyle(color: Colors.white)),
backgroundColor: const Color(0xFF00A900),
context: context,
));
// launch refilc url
Future.delayed(const Duration(seconds: 1), () {
Navigator.of(context).pop();
launchUrl(uri, mode: LaunchMode.inAppBrowserView);
});
} else {
// show invalid code error
// Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
content: Text("invalid_qr_code".i18n,
style: const TextStyle(color: Colors.white)),
backgroundColor: AppColors.of(context).red,
context: context,
));
controller.resumeCamera();
}
} else {
// show invalid code error
// Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
content: Text("invalid_qr_code".i18n,
style: const TextStyle(color: Colors.white)),
backgroundColor: AppColors.of(context).red,
context: context,
));
controller.resumeCamera();
}
// log(scanData.code);
// Provider.of<SyncProvider>(context, listen: false).syncAll(context);
}
});
}
void _onPermissionSet(BuildContext context, QRViewController ctrl, bool p) {
// log('${DateTime.now().toIso8601String()}_onPermissionSet $p');
if (!p) {
ScaffoldMessenger.of(context).showSnackBar(CustomSnackBar(
content: Text("camera_perm_error".i18n,