fix: qrcode issue and update qrcode lib

This commit is contained in:
hiddify-com
2024-07-14 16:32:08 +02:00
parent 076fc14758
commit 866ab7ee45
3 changed files with 29 additions and 24 deletions

View File

@@ -33,7 +33,7 @@ class QRCodeScannerScreen extends StatefulHookConsumerWidget {
class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> with WidgetsBindingObserver, PresLogger { class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> with WidgetsBindingObserver, PresLogger {
final MobileScannerController controller = MobileScannerController( final MobileScannerController controller = MobileScannerController(
detectionTimeoutMs: 500, detectionTimeoutMs: 500,
// autoStart: false, autoStart: false,
); );
bool started = false; bool started = false;
@@ -136,6 +136,8 @@ class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> with
} }
Future<void> _startScanner() async { Future<void> _startScanner() async {
loggy.info("Starting scanner");
await controller.stop();
await controller.start().whenComplete(() { await controller.start().whenComplete(() {
setState(() { setState(() {
started = true; started = true;
@@ -186,8 +188,6 @@ class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> with
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Translations t = ref.watch(translationsProvider); final Translations t = ref.watch(translationsProvider);
startQrScannerIfPermissionIsGranted();
return FutureBuilder( return FutureBuilder(
future: FlutterEasyPermission.has( future: FlutterEasyPermission.has(
perms: permissions, perms: permissions,
@@ -210,7 +210,7 @@ class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> with
Widget _buildScannerUI(BuildContext context, Translations t) { Widget _buildScannerUI(BuildContext context, Translations t) {
final size = MediaQuery.sizeOf(context); final size = MediaQuery.sizeOf(context);
final overlaySize = (size.shortestSide - 12).coerceAtMost(248); final overlaySize = (size.shortestSide - 12).coerceAtMost(248);
// _startScanner();
return Scaffold( return Scaffold(
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
appBar: AppBar( appBar: AppBar(
@@ -221,26 +221,31 @@ class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> with
), ),
actions: [ actions: [
IconButton( IconButton(
icon: ValueListenableBuilder( icon: const Icon(FluentIcons.flash_24_regular),
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, tooltip: t.profile.add.qrScanner.torchSemanticLabel,
onPressed: () => controller.toggleTorch(), 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( IconButton(
icon: const Icon(FluentIcons.camera_switch_24_regular), icon: const Icon(FluentIcons.camera_switch_24_regular),
tooltip: t.profile.add.qrScanner.facingSemanticLabel, tooltip: t.profile.add.qrScanner.facingSemanticLabel,

View File

@@ -1019,10 +1019,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: mobile_scanner name: mobile_scanner
sha256: "619ed5fd43ca9007a151f00c3dc43feedeaf235fe5647735d0237c38849d49dc" sha256: b8c0e9afcfd52534f85ec666f3d52156f560b5e6c25b1e3d4fe2087763607926
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.0.0" version: "5.1.1"
neat_periodic_task: neat_periodic_task:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@@ -35,7 +35,7 @@ dependencies:
dio: ^5.4.1 dio: ^5.4.1
ffi: ^2.1.2 ffi: ^2.1.2
path_provider: ^2.1.1 path_provider: ^2.1.1
mobile_scanner: ^4.0.0 mobile_scanner: ^5.1.1
protocol_handler: ^0.2.0 protocol_handler: ^0.2.0
flutter_native_splash: ^2.3.10 flutter_native_splash: ^2.3.10
share_plus: ^7.2.2 share_plus: ^7.2.2