-
-
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
feat: handle more facing directions #1328
Changes from all commits
2cbba5c
dff7932
ddeee0d
2cff3ca
8570dea
0125659
efa9d22
a6ffafc
0058760
c7cfd36
5d1daab
5d42a85
3be7291
5ee62da
c7abff4
28d3a5f
4f847df
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 |
---|---|---|
|
@@ -434,10 +434,18 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, | |
let answer: [String : Any?] | ||
|
||
if let device = self.device { | ||
let cameraDirection: Int? = switch(device.position) { | ||
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. Fun fact: MacOS reports |
||
case .back: 1 | ||
case .unspecified: nil | ||
case .front: 0 | ||
@unknown default: nil | ||
} | ||
|
||
answer = [ | ||
"textureId": self.textureId, | ||
"size": size, | ||
"currentTorchState": device.hasTorch ? device.torchMode.rawValue : -1, | ||
"cameraDirection": cameraDirection, | ||
] | ||
} else { | ||
answer = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart'; | |
import 'package:flutter/services.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:mobile_scanner/src/enums/barcode_format.dart'; | ||
import 'package:mobile_scanner/src/enums/camera_facing.dart'; | ||
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'; | ||
|
@@ -307,13 +308,16 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | |
); | ||
} | ||
|
||
final CameraFacing cameraDirection = | ||
CameraFacing.fromRawValue(startResult['cameraDirection'] as int?); | ||
|
||
_textureId = textureId; | ||
|
||
if (defaultTargetPlatform == TargetPlatform.android) { | ||
_surfaceProducerDelegate = | ||
AndroidSurfaceProducerDelegate.fromConfiguration( | ||
startResult, | ||
startOptions.cameraDirection, | ||
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. To stay consistent with the camera state, we should take the camera direction from the start result |
||
cameraDirection, | ||
); | ||
_surfaceProducerDelegate?.startListeningToDeviceOrientation( | ||
deviceOrientationChangedStream, | ||
|
@@ -337,6 +341,7 @@ class MethodChannelMobileScanner extends MobileScannerPlatform { | |
_pausing = false; | ||
|
||
return MobileScannerViewAttributes( | ||
cameraDirection: cameraDirection, | ||
currentTorchMode: currentTorchState, | ||
numberOfCameras: numberOfCameras, | ||
size: size, | ||
|
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 was done to keep the actual camera state in sync with the value