From 866ab7ee451b49686d03205236d914c15bb6fb4e Mon Sep 17 00:00:00 2001 From: hiddify-com <114227601+hiddify-com@users.noreply.github.com> Date: Sun, 14 Jul 2024 16:32:08 +0200 Subject: [PATCH] fix: qrcode issue and update qrcode lib --- .../common/qr_code_scanner_screen.dart | 47 ++++++++++--------- pubspec.lock | 4 +- pubspec.yaml | 2 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/lib/features/common/qr_code_scanner_screen.dart b/lib/features/common/qr_code_scanner_screen.dart index a698cef00..cde0f1f9b 100644 --- a/lib/features/common/qr_code_scanner_screen.dart +++ b/lib/features/common/qr_code_scanner_screen.dart @@ -33,7 +33,7 @@ class QRCodeScannerScreen extends StatefulHookConsumerWidget { class _QRCodeScannerScreenState extends ConsumerState with WidgetsBindingObserver, PresLogger { final MobileScannerController controller = MobileScannerController( detectionTimeoutMs: 500, - // autoStart: false, + autoStart: false, ); bool started = false; @@ -136,6 +136,8 @@ class _QRCodeScannerScreenState extends ConsumerState with } Future _startScanner() async { + loggy.info("Starting scanner"); + await controller.stop(); await controller.start().whenComplete(() { setState(() { started = true; @@ -186,8 +188,6 @@ class _QRCodeScannerScreenState extends ConsumerState with Widget build(BuildContext context) { final Translations t = ref.watch(translationsProvider); - startQrScannerIfPermissionIsGranted(); - return FutureBuilder( future: FlutterEasyPermission.has( perms: permissions, @@ -210,7 +210,7 @@ class _QRCodeScannerScreenState extends ConsumerState with Widget _buildScannerUI(BuildContext context, Translations t) { final size = MediaQuery.sizeOf(context); final overlaySize = (size.shortestSide - 12).coerceAtMost(248); - + // _startScanner(); return Scaffold( extendBodyBehindAppBar: true, appBar: AppBar( @@ -221,26 +221,31 @@ class _QRCodeScannerScreenState extends ConsumerState with ), actions: [ IconButton( - icon: ValueListenableBuilder( - valueListenable: controller.torchState, - builder: (context, state, child) { - switch (state) { - case TorchState.off: - return const Icon( - FluentIcons.flash_off_24_regular, - color: Colors.grey, - ); - case TorchState.on: - return const Icon( - FluentIcons.flash_24_regular, - color: Colors.yellow, - ); - } - }, - ), + icon: const Icon(FluentIcons.flash_24_regular), tooltip: t.profile.add.qrScanner.torchSemanticLabel, onPressed: () => controller.toggleTorch(), ), + // IconButton( + // icon: ValueListenableBuilder( + // valueListenable: controller.torchState, + // builder: (context, state, child) { + // switch (state) { + // case TorchState.off: + // return const Icon( + // FluentIcons.flash_off_24_regular, + // color: Colors.grey, + // ); + // case TorchState.on: + // return const Icon( + // FluentIcons.flash_24_regular, + // color: Colors.yellow, + // ); + // } + // }, + // ), + // tooltip: t.profile.add.qrScanner.torchSemanticLabel, + // onPressed: () => controller.toggleTorch(), + // ), IconButton( icon: const Icon(FluentIcons.camera_switch_24_regular), tooltip: t.profile.add.qrScanner.facingSemanticLabel, diff --git a/pubspec.lock b/pubspec.lock index 19dd22f09..845e1f499 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1019,10 +1019,10 @@ packages: dependency: "direct main" description: name: mobile_scanner - sha256: "619ed5fd43ca9007a151f00c3dc43feedeaf235fe5647735d0237c38849d49dc" + sha256: b8c0e9afcfd52534f85ec666f3d52156f560b5e6c25b1e3d4fe2087763607926 url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "5.1.1" neat_periodic_task: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index c6de1a5df..4f078b214 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,7 +35,7 @@ dependencies: dio: ^5.4.1 ffi: ^2.1.2 path_provider: ^2.1.1 - mobile_scanner: ^4.0.0 + mobile_scanner: ^5.1.1 protocol_handler: ^0.2.0 flutter_native_splash: ^2.3.10 share_plus: ^7.2.2