-
-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: correct android preview orientation #1329
Changes from all commits
e7e0a8a
e45ef54
47148b9
4a710ef
ab036ed
ed3a0bb
9ae1a30
1e5203a
ad1c312
8586736
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,7 +191,7 @@ class MobileScannerHandler( | |
"textureId" to it.id, | ||
"size" to mapOf("width" to it.width, "height" to it.height), | ||
"naturalDeviceOrientation" to it.naturalDeviceOrientation, | ||
"isPreviewPreTransformed" to it.isPreviewPreTransformed, | ||
"handlesCropAndRotation" to it.handlesCropAndRotation, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to match the actual name from the SurfaceProducer API. |
||
"sensorOrientation" to it.sensorOrientation, | ||
"currentTorchState" to it.currentTorchState, | ||
"numberOfCameras" to it.numberOfCameras, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ GeneratedPluginRegistrant.java | |
key.properties | ||
**/*.keystore | ||
**/*.jks | ||
|
||
**/.cxx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to add this line, since Flutter 3.29 would add a .cxx folder when compiling on Android. New |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ dependencies: | |
flutter: | ||
sdk: flutter | ||
|
||
image_picker: ^1.0.4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bumping image picker (and updating the pubspec.lock locally) fixed a build issue with the removal of the Android v1 embedding. |
||
image_picker: ^1.1.2 | ||
mobile_scanner: | ||
# When depending on this package from a real application you should use: | ||
# mobile_scanner: ^x.y.z | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import 'package:mobile_scanner/src/enums/mobile_scanner_authorization_state.dart | |
import 'package:mobile_scanner/src/enums/mobile_scanner_error_code.dart'; | ||
import 'package:mobile_scanner/src/enums/torch_state.dart'; | ||
import 'package:mobile_scanner/src/method_channel/android_surface_producer_delegate.dart'; | ||
import 'package:mobile_scanner/src/method_channel/rotated_preview.dart'; | ||
import 'package:mobile_scanner/src/mobile_scanner_exception.dart'; | ||
import 'package:mobile_scanner/src/mobile_scanner_platform_interface.dart'; | ||
import 'package:mobile_scanner/src/mobile_scanner_view_attributes.dart'; | ||
|
@@ -239,9 +240,20 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | |
|
||
final Widget texture = Texture(textureId: _textureId!); | ||
|
||
// If the preview needs manual orientation corrections, | ||
// correct the preview orientation based on the currently reported device orientation. | ||
// On Android, the underlying device orientation stream will emit the current orientation | ||
// when the first listener is attached. | ||
if (_surfaceProducerDelegate | ||
case final AndroidSurfaceProducerDelegate delegate) { | ||
return delegate.applyRotationCorrection(texture); | ||
case final AndroidSurfaceProducerDelegate delegate | ||
when !delegate.handlesCropAndRotation) { | ||
return RotatedPreview.fromCameraDirection( | ||
delegate.cameraFacingDirection, | ||
deviceOrientationStream: deviceOrientationChangedStream, | ||
initialDeviceOrientation: delegate.initialDeviceOrientation, | ||
sensorOrientationDegrees: delegate.sensorOrientationDegrees, | ||
child: texture, | ||
); | ||
} | ||
|
||
return texture; | ||
|
@@ -319,9 +331,6 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | |
startResult, | ||
cameraDirection, | ||
); | ||
_surfaceProducerDelegate?.startListeningToDeviceOrientation( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now handled by a separate widget. |
||
deviceOrientationChangedStream, | ||
); | ||
} | ||
|
||
final int? numberOfCameras = startResult['numberOfCameras'] as int?; | ||
|
@@ -356,7 +365,6 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | |
|
||
_textureId = null; | ||
_pausing = false; | ||
_surfaceProducerDelegate?.dispose(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The disposal of the "delegate" is no longer needed, since the stream subscription is moved to a widget. |
||
_surfaceProducerDelegate = null; | ||
|
||
await methodChannel.invokeMethod<void>('stop'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change that wasn't surfaced when using Kotlin 1.7, hence the bump to Kotlin 1.8. For some reason the compiler now checked for null specifically for this case (and probably others but I didn't see any changes). The bitmap config is provided when creating the original bitmap