Browse Source

hide flash button when device is not supported

pull/89/head
Khoren Markosyan 2 years ago
parent
commit
8cae06e3d6
  1. 2
      example/pubspec.lock
  2. 35
      lib/src/ui/reader_widget.dart
  3. 12
      zxscanner/pubspec.lock

2
example/pubspec.lock

@ -166,7 +166,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "1.0.0" version: "1.0.1"
http: http:
dependency: transitive dependency: transitive
description: description:

35
lib/src/ui/reader_widget.dart

@ -126,27 +126,27 @@ class _ReaderWidgetState extends State<ReaderWidget>
List<CameraDescription> cameras = <CameraDescription>[]; List<CameraDescription> cameras = <CameraDescription>[];
CameraDescription? selectedCamera; CameraDescription? selectedCamera;
CameraController? controller; 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 _zoom = 1.0;
double _scaleFactor = 1.0; double _scaleFactor = 1.0;
double _maxZoomLevel = 1.0; double _maxZoomLevel = 1.0;
double _minZoomLevel = 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(); Codes results = Codes();
bool isAndroid() => Theme.of(context).platform == TargetPlatform.android;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addObserver(this);
isMultiScan = widget.isMultiScan; _isMultiScan = widget.isMultiScan;
initStateAsync(); initStateAsync();
} }
@ -174,7 +174,7 @@ class _ReaderWidgetState extends State<ReaderWidget>
switch (state) { switch (state) {
case AppLifecycleState.resumed: case AppLifecycleState.resumed:
if (cameras.isNotEmpty && !_cameraOn) { if (cameras.isNotEmpty && !_isCameraOn) {
onNewCameraSelected(cameras.first); onNewCameraSelected(cameras.first);
} }
break; break;
@ -182,7 +182,7 @@ class _ReaderWidgetState extends State<ReaderWidget>
case AppLifecycleState.paused: case AppLifecycleState.paused:
controller?.dispose(); controller?.dispose();
setState(() { setState(() {
_cameraOn = false; _isCameraOn = false;
}); });
break; break;
case AppLifecycleState.detached: case AppLifecycleState.detached:
@ -202,7 +202,7 @@ class _ReaderWidgetState extends State<ReaderWidget>
void rebuildOnMount() { void rebuildOnMount() {
if (mounted) { if (mounted) {
setState(() { setState(() {
_cameraOn = true; _isCameraOn = true;
}); });
} }
} }
@ -239,6 +239,7 @@ class _ReaderWidgetState extends State<ReaderWidget>
try { try {
await cameraController.setFlashMode(FlashMode.off); await cameraController.setFlashMode(FlashMode.off);
} catch (e) { } catch (e) {
_isFlashAvailable = false;
debugPrint('Error: $e'); debugPrint('Error: $e');
} }
@ -316,7 +317,7 @@ class _ReaderWidgetState extends State<ReaderWidget>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final bool isCameraReady = cameras.isNotEmpty && final bool isCameraReady = cameras.isNotEmpty &&
_cameraOn && _isCameraOn &&
controller != null && controller != null &&
controller!.value.isInitialized; controller!.value.isInitialized;
final Size size = MediaQuery.of(context).size; final Size size = MediaQuery.of(context).size;
@ -389,7 +390,9 @@ class _ReaderWidgetState extends State<ReaderWidget>
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
if (widget.showFlashlight && isCameraReady) if (widget.showFlashlight &&
isCameraReady &&
_isFlashAvailable)
IconButton( IconButton(
onPressed: _onFlashButtonTapped, onPressed: _onFlashButtonTapped,
color: Colors.white, color: Colors.white,
@ -420,12 +423,12 @@ class _ReaderWidgetState extends State<ReaderWidget>
if (widget.onMultiScanModeChanged != null) if (widget.onMultiScanModeChanged != null)
SafeArea( SafeArea(
child: ScanModeDropdown( child: ScanModeDropdown(
isMultiScan: isMultiScan, isMultiScan: _isMultiScan,
alignment: widget.multiScanModeAlignment, alignment: widget.multiScanModeAlignment,
padding: widget.multiScanModePadding, padding: widget.multiScanModePadding,
onChanged: (bool value) { onChanged: (bool value) {
setState(() { setState(() {
isMultiScan = value; _isMultiScan = value;
}); });
widget.onMultiScanModeChanged?.call(value); widget.onMultiScanModeChanged?.call(value);
}, },

12
zxscanner/pubspec.lock

@ -77,10 +77,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: build_resolvers name: build_resolvers
sha256: "7c35a3a7868626257d8aee47b51c26b9dba11eaddf3431117ed2744951416aab" sha256: db49b8609ef8c81cca2b310618c3017c00f03a92af44c04d310b907b2d692d95
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.0" version: "2.2.0"
build_runner: build_runner:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -601,10 +601,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: mobx name: mobx
sha256: f1862bd92c6a903fab67338f27e2f731117c3cb9ea37cee1a487f9e4e0de314a sha256: "6738620307a424d2c9ad8b873f4dce391c44e9135eb4e75668ac8202fec7a9b8"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.3+1" version: "2.1.4"
mobx_codegen: mobx_codegen:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -934,10 +934,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: universal_io name: universal_io
sha256: "79f78ddad839ee3aae3ec7c01eb4575faf0d5c860f8e5223bc9f9c17f7f03cef" sha256: "06866290206d196064fd61df4c7aea1ffe9a4e7c4ccaa8fcded42dd41948005d"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.4" version: "2.2.0"
url_launcher: url_launcher:
dependency: "direct main" dependency: "direct main"
description: description:

Loading…
Cancel
Save