From 7b0cdb18dbe65186aac943a4b3cf49c6ba638585 Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Sun, 19 Jun 2022 15:06:18 +0400 Subject: [PATCH] show black screen if camera not found --- example/android/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 6 +- example/pubspec.lock | 20 +--- ios/Classes/src/native_zxing.cpp | 2 + lib/src/ui/reader_widget.dart | 102 +++++++++--------- pubspec.yaml | 2 +- zxscanner/pubspec.lock | 52 ++++----- zxscanner/pubspec.yaml | 6 +- 8 files changed, 84 insertions(+), 110 deletions(-) diff --git a/example/android/build.gradle b/example/android/build.gradle index 4256f91..27d3bd7 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.6.21' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:7.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index bc6a58a..7c62975 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jun 23 08:50:38 CEST 2017 +#Sat Jun 18 18:28:03 AMT 2022 distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +zipStoreBase=GRADLE_USER_HOME diff --git a/example/pubspec.lock b/example/pubspec.lock index 218a863..af05c23 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -28,21 +28,7 @@ packages: name: camera url: "https://pub.dartlang.org" source: hosted - version: "0.9.8" - camera_android: - dependency: transitive - description: - name: camera_android - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.7+1" - camera_avfoundation: - dependency: transitive - description: - name: camera_avfoundation - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.7+1" + version: "0.9.7" camera_platform_interface: dependency: transitive description: @@ -112,7 +98,7 @@ packages: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.2.1" + version: "2.0.0" flutter: dependency: "direct main" description: flutter @@ -197,7 +183,7 @@ packages: name: image_picker_android url: "https://pub.dartlang.org" source: hosted - version: "0.8.5" + version: "0.8.5+1" image_picker_for_web: dependency: transitive description: diff --git a/ios/Classes/src/native_zxing.cpp b/ios/Classes/src/native_zxing.cpp index 32cdf7d..da1d1cd 100644 --- a/ios/Classes/src/native_zxing.cpp +++ b/ios/Classes/src/native_zxing.cpp @@ -52,6 +52,7 @@ extern "C" size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t); code.text = new char[size]; std::wcstombs(code.text, resultText, size); + platform_log("zxingRead: %ls", resultText); } int evalInMillis = static_cast(get_now() - start); @@ -98,6 +99,7 @@ extern "C" codes[i] = code; i++; + platform_log("zxingRead: %s", code.text); } } diff --git a/lib/src/ui/reader_widget.dart b/lib/src/ui/reader_widget.dart index d1f0d92..332733e 100644 --- a/lib/src/ui/reader_widget.dart +++ b/lib/src/ui/reader_widget.dart @@ -199,17 +199,16 @@ class _ReaderWidgetState extends State // Display the preview from the camera. Widget _cameraPreviewWidget(double cropSize) { final CameraController? cameraController = controller; - if (cameras != null && (cameras?.isEmpty ?? false)) { - return const Text('No cameras found'); - } else if (cameraController == null || - !cameraController.value.isInitialized || - !_cameraOn) { - return const CircularProgressIndicator(); - } else { - final Size size = MediaQuery.of(context).size; - final double cameraMaxSize = max(size.width, size.height); - return Stack( - children: [ + final bool isCameraReady = cameras != null && + (cameras?.isNotEmpty ?? false) && + _cameraOn && + !(cameraController == null || !cameraController.value.isInitialized); + final Size size = MediaQuery.of(context).size; + final double cameraMaxSize = max(size.width, size.height); + return Stack( + children: [ + if (!isCameraReady) Container(color: Colors.black), + if (isCameraReady) SizedBox( width: cameraMaxSize, height: cameraMaxSize, @@ -227,37 +226,38 @@ class _ReaderWidgetState extends State ), ), ), - if (widget.showCroppingRect) - Container( - decoration: ShapeDecoration( - shape: widget.scannerOverlay ?? - ScannerOverlay( - borderColor: Theme.of(context).primaryColor, - overlayColor: Colors.black45, - borderRadius: 1, - borderLength: 16, - borderWidth: 8, - cutOutSize: cropSize, - ), - ), - ), - if (widget.allowPinchZoom) - GestureDetector( - onScaleStart: (ScaleStartDetails details) { - _zoom = _scaleFactor; - }, - onScaleUpdate: (ScaleUpdateDetails details) { - _scaleFactor = - (_zoom * details.scale).clamp(_minZoomLevel, _maxZoomLevel); - cameraController.setZoomLevel(_scaleFactor); - }, + if (widget.showCroppingRect) + Container( + decoration: ShapeDecoration( + shape: widget.scannerOverlay ?? + ScannerOverlay( + borderColor: Theme.of(context).primaryColor, + overlayColor: Colors.black45, + borderRadius: 1, + borderLength: 16, + borderWidth: 8, + cutOutSize: cropSize, + ), ), - if (widget.showFlashlight) - Positioned( - bottom: 20, - left: 20, - child: FloatingActionButton( - onPressed: () { + ), + if (widget.allowPinchZoom) + GestureDetector( + onScaleStart: (ScaleStartDetails details) { + _zoom = _scaleFactor; + }, + onScaleUpdate: (ScaleUpdateDetails details) { + _scaleFactor = + (_zoom * details.scale).clamp(_minZoomLevel, _maxZoomLevel); + cameraController?.setZoomLevel(_scaleFactor); + }, + ), + if (widget.showFlashlight) + Positioned( + bottom: 20, + left: 20, + child: FloatingActionButton( + onPressed: () { + if (cameraController != null) { FlashMode mode = cameraController.value.flashMode; if (mode == FlashMode.torch) { mode = FlashMode.off; @@ -266,18 +266,18 @@ class _ReaderWidgetState extends State } cameraController.setFlashMode(mode); setState(() {}); - }, - backgroundColor: Colors.black26, - child: Icon(_flashIcon(cameraController)), - ), - ) - ], - ); - } + } + }, + backgroundColor: Colors.black26, + child: Icon(_flashIcon(cameraController)), + ), + ) + ], + ); } - IconData _flashIcon(CameraController cameraController) { - final FlashMode mode = cameraController.value.flashMode; + IconData _flashIcon(CameraController? cameraController) { + final FlashMode mode = cameraController?.value.flashMode ?? FlashMode.torch; switch (mode) { case FlashMode.torch: return Icons.flash_on; diff --git a/pubspec.yaml b/pubspec.yaml index d67b1e5..c9d0706 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: camera: ^0.9.7 - ffi: ^1.2.1 + ffi: ^2.0.0 flutter: sdk: flutter flutter_beep: ^1.0.0 diff --git a/zxscanner/pubspec.lock b/zxscanner/pubspec.lock index 506a5f9..74bdbfb 100644 --- a/zxscanner/pubspec.lock +++ b/zxscanner/pubspec.lock @@ -98,28 +98,14 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.3.2" + version: "8.3.3" camera: dependency: transitive description: name: camera url: "https://pub.dartlang.org" source: hosted - version: "0.9.8" - camera_android: - dependency: transitive - description: - name: camera_android - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.7+1" - camera_avfoundation: - dependency: transitive - description: - name: camera_avfoundation - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.7+1" + version: "0.9.7" camera_platform_interface: dependency: transitive description: @@ -231,7 +217,7 @@ packages: name: ffi url: "https://pub.dartlang.org" source: hosted - version: "1.2.1" + version: "2.0.0" file: dependency: transitive description: @@ -297,7 +283,7 @@ packages: name: flutter_native_splash url: "https://pub.dartlang.org" source: hosted - version: "2.2.3" + version: "2.2.3+1" flutter_plugin_android_lifecycle: dependency: transitive description: @@ -342,7 +328,7 @@ packages: name: glob url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.1.0" graphs: dependency: transitive description: @@ -384,7 +370,7 @@ packages: name: http_multi_server url: "https://pub.dartlang.org" source: hosted - version: "3.2.0" + version: "3.2.1" http_parser: dependency: transitive description: @@ -419,7 +405,7 @@ packages: name: image_picker_android url: "https://pub.dartlang.org" source: hosted - version: "0.8.5" + version: "0.8.5+1" image_picker_for_web: dependency: transitive description: @@ -531,7 +517,7 @@ packages: name: mobx url: "https://pub.dartlang.org" source: hosted - version: "2.0.7+2" + version: "2.0.7+3" mobx_codegen: dependency: "direct dev" description: @@ -545,7 +531,7 @@ packages: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.1.0" path: dependency: transitive description: @@ -566,14 +552,14 @@ packages: name: path_provider_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.14" + version: "2.0.15" path_provider_ios: dependency: transitive description: name: path_provider_ios url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.0.10" path_provider_linux: dependency: transitive description: @@ -601,7 +587,7 @@ packages: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.7" + version: "2.1.0" petitparser: dependency: transitive description: @@ -629,7 +615,7 @@ packages: name: pool url: "https://pub.dartlang.org" source: hosted - version: "1.5.0" + version: "1.5.1" process: dependency: transitive description: @@ -664,7 +650,7 @@ packages: name: share_plus url: "https://pub.dartlang.org" source: hosted - version: "4.0.7" + version: "4.0.8" share_plus_linux: dependency: transitive description: @@ -762,14 +748,14 @@ packages: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.2" sky_engine: dependency: transitive description: flutter @@ -900,14 +886,14 @@ packages: name: url_launcher_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.1.0" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "2.0.11" + version: "2.0.12" url_launcher_windows: dependency: transitive description: @@ -942,7 +928,7 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.7.0" xdg_directories: dependency: transitive description: diff --git a/zxscanner/pubspec.yaml b/zxscanner/pubspec.yaml index e0b2ca1..0cf40f7 100644 --- a/zxscanner/pubspec.yaml +++ b/zxscanner/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: flutter_localizations: sdk: flutter flutter_markdown: ^0.6.10 - flutter_mobx: ^2.0.5 + flutter_mobx: ^2.0.6 flutter_zxing: path: ../ font_awesome_flutter: ^10.1.0 @@ -27,7 +27,7 @@ dependencies: intl: ^0.17.0 mobx: ^2.0.7 path_provider: ^2.0.11 - share_plus: ^4.0.7 + share_plus: ^4.0.8 shared_preferences: ^2.0.15 url_launcher: ^6.1.3 @@ -38,7 +38,7 @@ flutter_intl: dev_dependencies: build_runner: ^2.1.11 flutter_lints: ^2.0.1 - flutter_native_splash: ^2.2.2 # flutter pub run flutter_native_splash:create + flutter_native_splash: ^2.2.3 # flutter pub run flutter_native_splash:create flutter_test: sdk: flutter hive_generator: