How to handle device orientation changes #17
Replies: 10 comments 10 replies
-
After some experimenting I don't think you should be using an external library for this anyway. You need to tell the camera on the device to switch orientation as well so you need to edit the native code already. I've got a working mock up for iOS right now and will attempt Android shortly (I'm new to Swift and Kotlin). I created a new StreamController for orientation change and within the swift code sent the orientation if it had changed whenever captureOutput runs, at the same time this changes the orientation of the video preview accordingly. Within flutter the width and height of the SizedBox are reversed to get the correct size and an optional function OnChangeOrientation is exposed if the end user wants to do something more on orientation change. |
Beta Was this translation helpful? Give feedback.
-
@juliansteenbakker |
Beta Was this translation helpful? Give feedback.
-
After some experimenting, I do think the only way of testing for langscape left or right without native_device_orientation would be to implement very similar code in this project. While I do agree with and support the idea of using as little dependencies as possible, I'd personally rather have one more dependency that does on thing and does that thing very well, than having similar lower quality, lower possibility code added to this project directly. I've also tried using |
Beta Was this translation helpful? Give feedback.
-
In my app, the orientation for the entire app is locked to landscape left. Is there a way to force the scanner to be locked in that orientation as well? |
Beta Was this translation helpful? Give feedback.
-
Any update on this? I see several examples on the internet to rotate and scale the widget depending the current orientation. But the aspect ratio of the camera controller is used to calculate the scale of the widget in these examples. However I cannot find a similar aspect ratio value for the mobile scanner controller. `
Like in the above example, how can I detect the controller.value.aspectRatio for the mobile_scanner widget? |
Beta Was this translation helpful? Give feedback.
-
There is an older and seemingly now unmaintained scanning module on pub.dev that gets orientation and orientation change just right: flutter_barcode_scanner. Even if the last commit is about two years ago, i might still serve as a source of inspiration wrt orientation. (We used to use use flutter_barcode_scanner, but we now switched to mobile_scanner). |
Beta Was this translation helpful? Give feedback.
-
Not really a help for people who really need this, but when I reviewed Google Lens or my Camera App, I noticed that they locked the camera view in portrait mode. Only makes sense, because this will leave the axis in a correct and natural way. |
Beta Was this translation helpful? Give feedback.
-
So this may seem old to the conversation. But how about you let people set the orientation in the initializer for how they want it to display. Then if a user wants to implement their own rotation logic they can and just redraw the window. Then at that point you don't have to add a dependency, and the users can decide what orientations they want to support. You would also get backwards compatibility by leaving the default be what it is today. |
Beta Was this translation helpful? Give feedback.
-
Has the problem not been resolved yet? I also need to have it in landscape on the left, and the camera does not rotate. Has anyone managed to do something about this? |
Beta Was this translation helpful? Give feedback.
-
As a workaround I wrapped the MobileScanner with a RotatedBox widget as AspectRatio widget didn't work as expected for full width and used the native orientation package to detect the right and left landscape as mentioned in above replies to change the number of QuartedTurns value in RotatedBox widget. |
Beta Was this translation helpful? Give feedback.
-
Currently rotation is not supported.
We can't check for the right orientation since Flutters own orientation listener doesn't know the difference between landscape left or landscape right. This is why we can only rely on a plugin like native_device_orientation.
Another goal of this package is to use as few dependencies as possible. My question right now is if anyone knows a way we can detect for landscape left or landscape right, without the use of native_device_orientation.
Beta Was this translation helpful? Give feedback.
All reactions