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: ".."
relative: true
source: path
version: "1.0.0"
version: "1.0.1"
http:
dependency: transitive
description:

35
lib/src/ui/reader_widget.dart

@ -126,27 +126,27 @@ class _ReaderWidgetState extends State<ReaderWidget>
List<CameraDescription> cameras = <CameraDescription>[];
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<ReaderWidget>
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<ReaderWidget>
case AppLifecycleState.paused:
controller?.dispose();
setState(() {
_cameraOn = false;
_isCameraOn = false;
});
break;
case AppLifecycleState.detached:
@ -202,7 +202,7 @@ class _ReaderWidgetState extends State<ReaderWidget>
void rebuildOnMount() {
if (mounted) {
setState(() {
_cameraOn = true;
_isCameraOn = true;
});
}
}
@ -239,6 +239,7 @@ class _ReaderWidgetState extends State<ReaderWidget>
try {
await cameraController.setFlashMode(FlashMode.off);
} catch (e) {
_isFlashAvailable = false;
debugPrint('Error: $e');
}
@ -316,7 +317,7 @@ class _ReaderWidgetState extends State<ReaderWidget>
@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<ReaderWidget>
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (widget.showFlashlight && isCameraReady)
if (widget.showFlashlight &&
isCameraReady &&
_isFlashAvailable)
IconButton(
onPressed: _onFlashButtonTapped,
color: Colors.white,
@ -420,12 +423,12 @@ class _ReaderWidgetState extends State<ReaderWidget>
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);
},

12
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:

Loading…
Cancel
Save