Skip to content

Commit

Permalink
fix: qrcode issue and update qrcode lib
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jul 14, 2024
1 parent 076fc14 commit 866ab7e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
47 changes: 26 additions & 21 deletions lib/features/common/qr_code_scanner_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class QRCodeScannerScreen extends StatefulHookConsumerWidget {
class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> with WidgetsBindingObserver, PresLogger {
final MobileScannerController controller = MobileScannerController(
detectionTimeoutMs: 500,
// autoStart: false,
autoStart: false,
);
bool started = false;

Expand Down Expand Up @@ -136,6 +136,8 @@ class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> with
}

Future<void> _startScanner() async {
loggy.info("Starting scanner");
await controller.stop();
await controller.start().whenComplete(() {
setState(() {
started = true;
Expand Down Expand Up @@ -186,8 +188,6 @@ class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> with
Widget build(BuildContext context) {
final Translations t = ref.watch(translationsProvider);

startQrScannerIfPermissionIsGranted();

return FutureBuilder(
future: FlutterEasyPermission.has(
perms: permissions,
Expand All @@ -210,7 +210,7 @@ class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> 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(
Expand All @@ -221,26 +221,31 @@ class _QRCodeScannerScreenState extends ConsumerState<QRCodeScannerScreen> 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,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 866ab7e

Please sign in to comment.