Browse Source

show black screen if camera not found

pull/5/head
Khoren Markosyan 3 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 {
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"
}
}

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

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

2
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<int>(get_now() - start);
@ -98,6 +99,7 @@ extern "C"
codes[i] = code;
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.
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: <Widget>[
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: <Widget>[
if (!isCameraReady) Container(color: Colors.black),
if (isCameraReady)
SizedBox(
width: cameraMaxSize,
height: cameraMaxSize,
@ -227,37 +226,38 @@ class _ReaderWidgetState extends State<ReaderWidget>
),
),
),
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<ReaderWidget>
}
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;

2
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

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

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

Loading…
Cancel
Save