Browse Source

show black screen if camera not found

pull/5/head
Khoren Markosyan 2 years ago
parent
commit
7b0cdb18db
  1. 4
      example/android/build.gradle
  2. 6
      example/android/gradle/wrapper/gradle-wrapper.properties
  3. 20
      example/pubspec.lock
  4. 2
      ios/Classes/src/native_zxing.cpp
  5. 102
      lib/src/ui/reader_widget.dart
  6. 2
      pubspec.yaml
  7. 52
      zxscanner/pubspec.lock
  8. 6
      zxscanner/pubspec.yaml

4
example/android/build.gradle

@ -1,12 +1,12 @@
buildscript { buildscript {
ext.kotlin_version = '1.6.10' ext.kotlin_version = '1.6.21'
repositories { repositories {
google() google()
mavenCentral() mavenCentral()
} }
dependencies { 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" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
} }
} }

6
example/android/gradle/wrapper/gradle-wrapper.properties vendored

@ -1,6 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017 #Sat Jun 18 18:28:03 AMT 2022
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip zipStoreBase=GRADLE_USER_HOME

20
example/pubspec.lock

@ -28,21 +28,7 @@ packages:
name: camera name: camera
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.9.8" version: "0.9.7"
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"
camera_platform_interface: camera_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -112,7 +98,7 @@ packages:
name: ffi name: ffi
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.1" version: "2.0.0"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -197,7 +183,7 @@ packages:
name: image_picker_android name: image_picker_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.5" version: "0.8.5+1"
image_picker_for_web: image_picker_for_web:
dependency: transitive dependency: transitive
description: description:

2
ios/Classes/src/native_zxing.cpp

@ -52,6 +52,7 @@ extern "C"
size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t); size_t size = (wcslen(resultText) + 1) * sizeof(wchar_t);
code.text = new char[size]; code.text = new char[size];
std::wcstombs(code.text, resultText, size); std::wcstombs(code.text, resultText, size);
platform_log("zxingRead: %ls", resultText);
} }
int evalInMillis = static_cast<int>(get_now() - start); int evalInMillis = static_cast<int>(get_now() - start);
@ -98,6 +99,7 @@ extern "C"
codes[i] = code; codes[i] = code;
i++; i++;
platform_log("zxingRead: %s", code.text);
} }
} }

102
lib/src/ui/reader_widget.dart

@ -199,17 +199,16 @@ class _ReaderWidgetState extends State<ReaderWidget>
// Display the preview from the camera. // Display the preview from the camera.
Widget _cameraPreviewWidget(double cropSize) { Widget _cameraPreviewWidget(double cropSize) {
final CameraController? cameraController = controller; final CameraController? cameraController = controller;
if (cameras != null && (cameras?.isEmpty ?? false)) { final bool isCameraReady = cameras != null &&
return const Text('No cameras found'); (cameras?.isNotEmpty ?? false) &&
} else if (cameraController == null || _cameraOn &&
!cameraController.value.isInitialized || !(cameraController == null || !cameraController.value.isInitialized);
!_cameraOn) { final Size size = MediaQuery.of(context).size;
return const CircularProgressIndicator(); final double cameraMaxSize = max(size.width, size.height);
} else { return Stack(
final Size size = MediaQuery.of(context).size; children: <Widget>[
final double cameraMaxSize = max(size.width, size.height); if (!isCameraReady) Container(color: Colors.black),
return Stack( if (isCameraReady)
children: <Widget>[
SizedBox( SizedBox(
width: cameraMaxSize, width: cameraMaxSize,
height: cameraMaxSize, height: cameraMaxSize,
@ -227,37 +226,38 @@ class _ReaderWidgetState extends State<ReaderWidget>
), ),
), ),
), ),
if (widget.showCroppingRect) if (widget.showCroppingRect)
Container( Container(
decoration: ShapeDecoration( decoration: ShapeDecoration(
shape: widget.scannerOverlay ?? shape: widget.scannerOverlay ??
ScannerOverlay( ScannerOverlay(
borderColor: Theme.of(context).primaryColor, borderColor: Theme.of(context).primaryColor,
overlayColor: Colors.black45, overlayColor: Colors.black45,
borderRadius: 1, borderRadius: 1,
borderLength: 16, borderLength: 16,
borderWidth: 8, borderWidth: 8,
cutOutSize: cropSize, 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.showFlashlight) ),
Positioned( if (widget.allowPinchZoom)
bottom: 20, GestureDetector(
left: 20, onScaleStart: (ScaleStartDetails details) {
child: FloatingActionButton( _zoom = _scaleFactor;
onPressed: () { },
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; FlashMode mode = cameraController.value.flashMode;
if (mode == FlashMode.torch) { if (mode == FlashMode.torch) {
mode = FlashMode.off; mode = FlashMode.off;
@ -266,18 +266,18 @@ class _ReaderWidgetState extends State<ReaderWidget>
} }
cameraController.setFlashMode(mode); cameraController.setFlashMode(mode);
setState(() {}); setState(() {});
}, }
backgroundColor: Colors.black26, },
child: Icon(_flashIcon(cameraController)), backgroundColor: Colors.black26,
), child: Icon(_flashIcon(cameraController)),
) ),
], )
); ],
} );
} }
IconData _flashIcon(CameraController cameraController) { IconData _flashIcon(CameraController? cameraController) {
final FlashMode mode = cameraController.value.flashMode; final FlashMode mode = cameraController?.value.flashMode ?? FlashMode.torch;
switch (mode) { switch (mode) {
case FlashMode.torch: case FlashMode.torch:
return Icons.flash_on; return Icons.flash_on;

2
pubspec.yaml

@ -9,7 +9,7 @@ environment:
dependencies: dependencies:
camera: ^0.9.7 camera: ^0.9.7
ffi: ^1.2.1 ffi: ^2.0.0
flutter: flutter:
sdk: flutter sdk: flutter
flutter_beep: ^1.0.0 flutter_beep: ^1.0.0

52
zxscanner/pubspec.lock

@ -98,28 +98,14 @@ packages:
name: built_value name: built_value
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "8.3.2" version: "8.3.3"
camera: camera:
dependency: transitive dependency: transitive
description: description:
name: camera name: camera
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.9.8" version: "0.9.7"
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"
camera_platform_interface: camera_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -231,7 +217,7 @@ packages:
name: ffi name: ffi
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.1" version: "2.0.0"
file: file:
dependency: transitive dependency: transitive
description: description:
@ -297,7 +283,7 @@ packages:
name: flutter_native_splash name: flutter_native_splash
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.2.3" version: "2.2.3+1"
flutter_plugin_android_lifecycle: flutter_plugin_android_lifecycle:
dependency: transitive dependency: transitive
description: description:
@ -342,7 +328,7 @@ packages:
name: glob name: glob
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.2" version: "2.1.0"
graphs: graphs:
dependency: transitive dependency: transitive
description: description:
@ -384,7 +370,7 @@ packages:
name: http_multi_server name: http_multi_server
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.2.0" version: "3.2.1"
http_parser: http_parser:
dependency: transitive dependency: transitive
description: description:
@ -419,7 +405,7 @@ packages:
name: image_picker_android name: image_picker_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.5" version: "0.8.5+1"
image_picker_for_web: image_picker_for_web:
dependency: transitive dependency: transitive
description: description:
@ -531,7 +517,7 @@ packages:
name: mobx name: mobx
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.7+2" version: "2.0.7+3"
mobx_codegen: mobx_codegen:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -545,7 +531,7 @@ packages:
name: package_config name: package_config
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.2" version: "2.1.0"
path: path:
dependency: transitive dependency: transitive
description: description:
@ -566,14 +552,14 @@ packages:
name: path_provider_android name: path_provider_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.14" version: "2.0.15"
path_provider_ios: path_provider_ios:
dependency: transitive dependency: transitive
description: description:
name: path_provider_ios name: path_provider_ios
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.9" version: "2.0.10"
path_provider_linux: path_provider_linux:
dependency: transitive dependency: transitive
description: description:
@ -601,7 +587,7 @@ packages:
name: path_provider_windows name: path_provider_windows
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.7" version: "2.1.0"
petitparser: petitparser:
dependency: transitive dependency: transitive
description: description:
@ -629,7 +615,7 @@ packages:
name: pool name: pool
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.5.0" version: "1.5.1"
process: process:
dependency: transitive dependency: transitive
description: description:
@ -664,7 +650,7 @@ packages:
name: share_plus name: share_plus
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.0.7" version: "4.0.8"
share_plus_linux: share_plus_linux:
dependency: transitive dependency: transitive
description: description:
@ -762,14 +748,14 @@ packages:
name: shelf name: shelf
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.0" version: "1.3.1"
shelf_web_socket: shelf_web_socket:
dependency: transitive dependency: transitive
description: description:
name: shelf_web_socket name: shelf_web_socket
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.1" version: "1.0.2"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -900,14 +886,14 @@ packages:
name: url_launcher_platform_interface name: url_launcher_platform_interface
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.5" version: "2.1.0"
url_launcher_web: url_launcher_web:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_web name: url_launcher_web
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.11" version: "2.0.12"
url_launcher_windows: url_launcher_windows:
dependency: transitive dependency: transitive
description: description:
@ -942,7 +928,7 @@ packages:
name: win32 name: win32
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.6.1" version: "2.7.0"
xdg_directories: xdg_directories:
dependency: transitive dependency: transitive
description: description:

6
zxscanner/pubspec.yaml

@ -16,7 +16,7 @@ dependencies:
flutter_localizations: flutter_localizations:
sdk: flutter sdk: flutter
flutter_markdown: ^0.6.10 flutter_markdown: ^0.6.10
flutter_mobx: ^2.0.5 flutter_mobx: ^2.0.6
flutter_zxing: flutter_zxing:
path: ../ path: ../
font_awesome_flutter: ^10.1.0 font_awesome_flutter: ^10.1.0
@ -27,7 +27,7 @@ dependencies:
intl: ^0.17.0 intl: ^0.17.0
mobx: ^2.0.7 mobx: ^2.0.7
path_provider: ^2.0.11 path_provider: ^2.0.11
share_plus: ^4.0.7 share_plus: ^4.0.8
shared_preferences: ^2.0.15 shared_preferences: ^2.0.15
url_launcher: ^6.1.3 url_launcher: ^6.1.3
@ -38,7 +38,7 @@ flutter_intl:
dev_dependencies: dev_dependencies:
build_runner: ^2.1.11 build_runner: ^2.1.11
flutter_lints: ^2.0.1 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: flutter_test:
sdk: flutter sdk: flutter
hive_generator: hive_generator:

Loading…
Cancel
Save