Skip to content

Commit

Permalink
Fix no error reported on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoogstraat committed Oct 23, 2021
1 parent a049a26 commit dea7e93
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions fast_barcode_scanner/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.1.4

- Fixes `pauseDetector` on iOS
- Fixes no error reported when permissions are denied on Android
- Updates CameraX (compileSdk is now 31)

## 1.1.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class BarcodeReader(private val flutterTextureEntry: TextureRegistry.SurfaceText
/* State */
private var isInitialized = false
private var pauseDetection = false
private var pendingResult: Result? = null

fun attachToActivity(activity: Activity) {
this.activity = activity
Expand Down Expand Up @@ -75,15 +76,15 @@ class BarcodeReader(private val flutterTextureEntry: TextureRegistry.SurfaceText

if (allPermissionsGranted()) {
initCamera()
result.success(hashMapOf("textureId" to flutterTextureEntry.id(), "surfaceOrientation" to 0, "surfaceHeight" to 1280, "surfaceWidth" to 720))
} else {
pendingResult = result
ActivityCompat.requestPermissions(
activity!!,
REQUIRED_PERMISSIONS,
REQUEST_CODE_PERMISSIONS
)
}

result.success(hashMapOf("textureId" to flutterTextureEntry.id(), "surfaceOrientation" to 0, "surfaceHeight" to 1280, "surfaceWidth" to 720))
}

fun stop(result: Result? = null) {
Expand Down Expand Up @@ -113,6 +114,11 @@ class BarcodeReader(private val flutterTextureEntry: TextureRegistry.SurfaceText
if (requestCode == REQUEST_CODE_PERMISSIONS) {
if (grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
initCamera()
} else {
pendingResult?.let {
it.error("UNAUTHORIZED", "The application is not authorized to use the camera device", null)
pendingResult = null
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions fast_barcode_scanner/lib/src/barcode_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import 'package:flutter/rendering.dart';
typedef ErrorCallback = Widget Function(BuildContext context, Object? error);

Widget _defaultOnError(BuildContext context, Object? error) {
debugPrint("Error reading from camera: $error");
return const Center(child: Text("Error reading from camera..."));
return const Center(
child: Text(
"Error reading from camera...",
style: TextStyle(color: Colors.white),
));
}

/// The main class connecting the platform code to the UI.
Expand Down

0 comments on commit dea7e93

Please sign in to comment.