Merge pull request #143 from r4khul/feat/flash
Add QR scanner torch control using MobileScannerController
This commit is contained in:
commit
c143f228fe
1 changed files with 31 additions and 0 deletions
|
|
@ -12,8 +12,21 @@ class QrCodeScreen extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _QrCodeScreenState extends State<QrCodeScreen> {
|
class _QrCodeScreenState extends State<QrCodeScreen> {
|
||||||
|
late final MobileScannerController _controller;
|
||||||
bool _scanned = false;
|
bool _scanned = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller = MobileScannerController();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
void _onDetect(BarcodeCapture capture) async {
|
void _onDetect(BarcodeCapture capture) async {
|
||||||
if (_scanned) return;
|
if (_scanned) return;
|
||||||
final barcode = capture.barcodes.first;
|
final barcode = capture.barcodes.first;
|
||||||
|
|
@ -31,8 +44,26 @@ class _QrCodeScreenState extends State<QrCodeScreen> {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(AppLocalizations.of(context)!.settingsTitle),
|
title: Text(AppLocalizations.of(context)!.settingsTitle),
|
||||||
|
actions: [
|
||||||
|
ValueListenableBuilder<MobileScannerState>(
|
||||||
|
valueListenable: _controller,
|
||||||
|
builder: (context, state, _) {
|
||||||
|
return IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
state.torchState == TorchState.on
|
||||||
|
? Icons.flash_on
|
||||||
|
: Icons.flash_off,
|
||||||
|
),
|
||||||
|
onPressed: state.torchState == TorchState.unavailable
|
||||||
|
? null
|
||||||
|
: () => _controller.toggleTorch(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
body: MobileScanner(
|
body: MobileScanner(
|
||||||
|
controller: _controller,
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
onDetect: _onDetect,
|
onDetect: _onDetect,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue