From 8cae06e3d6cb29d1df0fcfbc927d3d5547747fe2 Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Fri, 17 Feb 2023 11:14:32 +0400 Subject: [PATCH] hide flash button when device is not supported --- example/pubspec.lock | 2 +- lib/src/ui/reader_widget.dart | 35 +++++++++++++++++++---------------- zxscanner/pubspec.lock | 12 ++++++------ 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 001075b..309f701 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -166,7 +166,7 @@ packages: path: ".." relative: true source: path - version: "1.0.0" + version: "1.0.1" http: dependency: transitive description: diff --git a/lib/src/ui/reader_widget.dart b/lib/src/ui/reader_widget.dart index 93170c5..c96ce86 100644 --- a/lib/src/ui/reader_widget.dart +++ b/lib/src/ui/reader_widget.dart @@ -126,27 +126,27 @@ class _ReaderWidgetState extends State List cameras = []; CameraDescription? selectedCamera; CameraController? controller; - bool _cameraOn = false; + + // true when code detecting is ongoing + bool _isProcessing = false; + bool _isCameraOn = false; + bool _isFlashAvailable = true; + bool _isMultiScan = false; double _zoom = 1.0; double _scaleFactor = 1.0; double _maxZoomLevel = 1.0; double _minZoomLevel = 1.0; - bool isAndroid() => Theme.of(context).platform == TargetPlatform.android; - - // true when code detecting is ongoing - bool _isProcessing = false; - - bool isMultiScan = false; - Codes results = Codes(); + bool isAndroid() => Theme.of(context).platform == TargetPlatform.android; + @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); - isMultiScan = widget.isMultiScan; + _isMultiScan = widget.isMultiScan; initStateAsync(); } @@ -174,7 +174,7 @@ class _ReaderWidgetState extends State switch (state) { case AppLifecycleState.resumed: - if (cameras.isNotEmpty && !_cameraOn) { + if (cameras.isNotEmpty && !_isCameraOn) { onNewCameraSelected(cameras.first); } break; @@ -182,7 +182,7 @@ class _ReaderWidgetState extends State case AppLifecycleState.paused: controller?.dispose(); setState(() { - _cameraOn = false; + _isCameraOn = false; }); break; case AppLifecycleState.detached: @@ -202,7 +202,7 @@ class _ReaderWidgetState extends State void rebuildOnMount() { if (mounted) { setState(() { - _cameraOn = true; + _isCameraOn = true; }); } } @@ -239,6 +239,7 @@ class _ReaderWidgetState extends State try { await cameraController.setFlashMode(FlashMode.off); } catch (e) { + _isFlashAvailable = false; debugPrint('Error: $e'); } @@ -316,7 +317,7 @@ class _ReaderWidgetState extends State @override Widget build(BuildContext context) { final bool isCameraReady = cameras.isNotEmpty && - _cameraOn && + _isCameraOn && controller != null && controller!.value.isInitialized; final Size size = MediaQuery.of(context).size; @@ -389,7 +390,9 @@ class _ReaderWidgetState extends State child: Row( mainAxisSize: MainAxisSize.min, children: [ - if (widget.showFlashlight && isCameraReady) + if (widget.showFlashlight && + isCameraReady && + _isFlashAvailable) IconButton( onPressed: _onFlashButtonTapped, color: Colors.white, @@ -420,12 +423,12 @@ class _ReaderWidgetState extends State if (widget.onMultiScanModeChanged != null) SafeArea( child: ScanModeDropdown( - isMultiScan: isMultiScan, + isMultiScan: _isMultiScan, alignment: widget.multiScanModeAlignment, padding: widget.multiScanModePadding, onChanged: (bool value) { setState(() { - isMultiScan = value; + _isMultiScan = value; }); widget.onMultiScanModeChanged?.call(value); }, diff --git a/zxscanner/pubspec.lock b/zxscanner/pubspec.lock index 2342760..48f9ccd 100644 --- a/zxscanner/pubspec.lock +++ b/zxscanner/pubspec.lock @@ -77,10 +77,10 @@ packages: dependency: transitive description: name: build_resolvers - sha256: "7c35a3a7868626257d8aee47b51c26b9dba11eaddf3431117ed2744951416aab" + sha256: db49b8609ef8c81cca2b310618c3017c00f03a92af44c04d310b907b2d692d95 url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.2.0" build_runner: dependency: "direct dev" description: @@ -601,10 +601,10 @@ packages: dependency: "direct main" description: name: mobx - sha256: f1862bd92c6a903fab67338f27e2f731117c3cb9ea37cee1a487f9e4e0de314a + sha256: "6738620307a424d2c9ad8b873f4dce391c44e9135eb4e75668ac8202fec7a9b8" url: "https://pub.dev" source: hosted - version: "2.1.3+1" + version: "2.1.4" mobx_codegen: dependency: "direct dev" description: @@ -934,10 +934,10 @@ packages: dependency: transitive description: name: universal_io - sha256: "79f78ddad839ee3aae3ec7c01eb4575faf0d5c860f8e5223bc9f9c17f7f03cef" + sha256: "06866290206d196064fd61df4c7aea1ffe9a4e7c4ccaa8fcded42dd41948005d" url: "https://pub.dev" source: hosted - version: "2.0.4" + version: "2.2.0" url_launcher: dependency: "direct main" description: