From 414755c777effd28e312d3e63c958c19aa1d8156 Mon Sep 17 00:00:00 2001 From: Kima Date: Wed, 13 Nov 2024 20:51:24 +0100 Subject: [PATCH] okay that's it bye --- refilc/lib/api/providers/sync.dart | 4 +- .../settings/settings_screen.i18n.dart | 3 + .../settings/submenu/code_scanner.dart | 68 +++++++++---------- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/refilc/lib/api/providers/sync.dart b/refilc/lib/api/providers/sync.dart index 94b28d4..81fca47 100644 --- a/refilc/lib/api/providers/sync.dart +++ b/refilc/lib/api/providers/sync.dart @@ -59,8 +59,8 @@ Future 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())) { diff --git a/refilc_mobile_ui/lib/screens/settings/settings_screen.i18n.dart b/refilc_mobile_ui/lib/screens/settings/settings_screen.i18n.dart index a2a5e8f..928d576 100644 --- a/refilc_mobile_ui/lib/screens/settings/settings_screen.i18n.dart +++ b/refilc_mobile_ui/lib/screens/settings/settings_screen.i18n.dart @@ -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!", }, }; diff --git a/refilc_mobile_ui/lib/screens/settings/submenu/code_scanner.dart b/refilc_mobile_ui/lib/screens/settings/submenu/code_scanner.dart index 132f9d1..ebae250 100644 --- a/refilc_mobile_ui/lib/screens/settings/submenu/code_scanner.dart +++ b/refilc_mobile_ui/lib/screens/settings/submenu/code_scanner.dart @@ -20,8 +20,6 @@ class _CodeScannerScreenState extends State { 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 { ], ), body: _buildQrView(context), - // body: Column( - // children: [ - // Expanded(flex: 4, child: _buildQrView(context)), - // // Expanded( - // // flex: 1, - // // child: FittedBox( - // // fit: BoxFit.contain, - // // child: Column( - // // mainAxisAlignment: MainAxisAlignment.spaceEvenly, - // // children: [ - // // 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 { 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 { // 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(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,