From 79cc43da0d723c7572ec6dbe70a0c3d3b801278b Mon Sep 17 00:00:00 2001 From: r4khul Date: Wed, 4 Feb 2026 13:15:24 +0530 Subject: [PATCH 1/2] Add QR scanner torch control using MobileScannerController --- lib/qr_code_screen.dart | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/qr_code_screen.dart b/lib/qr_code_screen.dart index e78131d..8dc8f49 100644 --- a/lib/qr_code_screen.dart +++ b/lib/qr_code_screen.dart @@ -12,8 +12,21 @@ class QrCodeScreen extends StatefulWidget { } class _QrCodeScreenState extends State { + late final MobileScannerController _controller; bool _scanned = false; + @override + void initState() { + super.initState(); + _controller = MobileScannerController(); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + void _onDetect(BarcodeCapture capture) async { if (_scanned) return; final barcode = capture.barcodes.first; @@ -31,8 +44,27 @@ class _QrCodeScreenState extends State { return Scaffold( appBar: AppBar( title: Text(AppLocalizations.of(context)!.settingsTitle), + actions: [ + ValueListenableBuilder( + valueListenable: _controller, + builder: (context, state, _) { + final torchState = state.torchState; + return IconButton( + icon: Icon( + torchState == TorchState.on + ? Icons.flash_on + : Icons.flash_off, + ), + onPressed: torchState == TorchState.unavailable + ? null + : () => _controller.toggleTorch(), + ); + }, + ), + ], ), body: MobileScanner( + controller: _controller, fit: BoxFit.cover, onDetect: _onDetect, ), From fc640eade09a5d8720f4be45e84175bdefc8c423 Mon Sep 17 00:00:00 2001 From: r4khul Date: Wed, 4 Feb 2026 20:24:10 +0530 Subject: [PATCH 2/2] Remove torchState variable in ValueListenableBuilder --- lib/qr_code_screen.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/qr_code_screen.dart b/lib/qr_code_screen.dart index 8dc8f49..05f9295 100644 --- a/lib/qr_code_screen.dart +++ b/lib/qr_code_screen.dart @@ -48,14 +48,13 @@ class _QrCodeScreenState extends State { ValueListenableBuilder( valueListenable: _controller, builder: (context, state, _) { - final torchState = state.torchState; return IconButton( icon: Icon( - torchState == TorchState.on + state.torchState == TorchState.on ? Icons.flash_on : Icons.flash_off, ), - onPressed: torchState == TorchState.unavailable + onPressed: state.torchState == TorchState.unavailable ? null : () => _controller.toggleTorch(), );